worker prints start success but no attachment yet

This commit is contained in:
Nathan
2025-12-17 16:32:39 -07:00
parent 4628fafc79
commit 0460865ebc
10 changed files with 7160 additions and 45 deletions

View File

@@ -197,12 +197,15 @@ namespace UnifiedFarmLauncher.Services
var sshArgs = BuildSshArgs(parts, interactive);
sshArgs.Add(command);
var argsString = string.Join(" ", sshArgs.Select(arg => $"\"{arg.Replace("\"", "\\\"")}\""));
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = GetSshExecutable(),
Arguments = string.Join(" ", sshArgs.Select(arg => $"\"{arg.Replace("\"", "\\\"")}\"")),
WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
Arguments = argsString,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
@@ -230,6 +233,54 @@ namespace UnifiedFarmLauncher.Services
return output.ToString();
}
public async Task<string> ExecuteRemoteScriptAsync(WorkerConfig worker, string script, bool interactive = false)
{
var parts = ParseConnectionParts(worker.Ssh.Args, worker.Ssh.Host);
var sshArgs = BuildSshArgs(parts, interactive);
// Add PowerShell command as a single quoted argument for remote execution
sshArgs.Add("powershell -NoLogo -NoProfile -NonInteractive -OutputFormat Text -ExecutionPolicy Bypass -Command -");
var argsString = string.Join(" ", sshArgs.Select(arg => $"\"{arg.Replace("\"", "\\\"")}\""));
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = GetSshExecutable(),
WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
Arguments = argsString,
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = !interactive
}
};
var output = new StringBuilder();
var error = new StringBuilder();
process.OutputDataReceived += (s, e) => { if (e.Data != null) output.AppendLine(e.Data); };
process.ErrorDataReceived += (s, e) => { if (e.Data != null) error.AppendLine(e.Data); };
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// Write script to stdin
await process.StandardInput.WriteAsync(script);
process.StandardInput.Close();
await process.WaitForExitAsync();
if (process.ExitCode != 0 && !interactive)
{
throw new InvalidOperationException($"SSH script execution failed with exit code {process.ExitCode}: {error}");
}
return output.ToString();
}
public async Task<string> GetWorkerBasePathAsync(WorkerConfig worker)
{
if (_workerBasePathCache.TryGetValue(worker.Name, out var cached))