Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public Guid StartEosNode()
        {
            var config         = JsonConvert.DeserializeObject <Config>(File.ReadAllText("config.json"));
            var pluginsCommand = string.Join(' ', config.plugins.Select(x => $"--plugin {x}"));
            var startInfo      = new ProcessStartInfo("/opt/eosio/bin/nodeos", $"-e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --http-validate-host=false");

            _oneboxProc = _proc.StartProcess(startInfo, async(id, x) => {
                try
                {
                    //await _hub.Clients.All.SendAsync("onLogReceived", id, x.IsError, x.Text);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("[Agent] " + ex.ToString());
                }
            }, "nodeos");
            Task.Factory.StartNew(() => {
                // Start bash to launch nodeos
                _oneboxProc.Process.Start();
                _oneboxProc.Process.WaitForExit();
            }).ConfigureAwait(false);
            return(_oneboxProc.Id);
        }
Exemplo n.º 3
0
 public void ForceShutdown()
 {
     ExecuteCommand("kill -15 " + _oneboxProc.Process.Id);
     _oneboxProc = null;
 }