public OneBoxProcess StartProcess(ProcessStartInfo startInfo, Action <Guid, Log> pushLogFunc = null, string alias = null) { var ret = new OneBoxProcess() { Alias = alias, Id = Guid.NewGuid() }; var process = new Process(); startInfo.RedirectStandardError = true; startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; process.StartInfo = startInfo; process.ErrorDataReceived += (sender, e) => { var log = new Log { IsError = true, ProcessId = process.Id, Text = e.Data }; ret.Logs.Add(log); pushLogFunc?.Invoke(ret.Id, log); }; process.OutputDataReceived += (sender, e) => { var log = new Log { IsError = false, ProcessId = process.Id, Text = e.Data }; ret.Logs.Add(log); pushLogFunc?.Invoke(ret.Id, log); }; _dic.Add(ret.Id, ret); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); return(ret); }
public Guid StartEosNode() { var config = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json")); var pluginsCommand = string.Join(' ', config.eos.plugins.Select(x => $"--plugin {x}")); var startInfo = new ProcessStartInfo("/opt/eosio/bin/nodeos", $"-e -p eosio {pluginsCommand} -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console --http-validate-host=false --delete-all-blocks"); _oneboxProc = _proc.StartProcess(startInfo, async(id, x) => { try { await _hub.Clients.All.SendAsync("onLogReceived", id, x.IsError, x.Text); } catch (Exception ex) { Console.WriteLine("[Dasdaq Dev Agent] " + ex.ToString()); } }, "nodeos"); Task.Factory.StartNew(() => { // Start bash to launch nodeos _oneboxProc.Process.Start(); _oneboxProc.Process.WaitForExit(); }).ConfigureAwait(false); return(_oneboxProc.Id); }
public void ForceShutdown() { ExecuteCommand("kill -15 " + _oneboxProc.Process.Id); _oneboxProc = null; }