private Task <ExecuteDos.ProcessResult> IssueIpfsNativeCommand(DosProcessContext ipfsProcessContext) { var ipfsexe = Instance.NativeExecutable; if (!ipfsexe.Exists) { L.Info("Could not find ipfs executable @ " + ipfsexe.FullName); return(null); } var dosContext = _dosContext = new ExecuteDos.DosContext(ipfsexe.FullName, ipfsProcessContext.Command) { OnProcessCreated = ipfsProcessContext.OnProcessCreated, OnProcessEnded = ipfsProcessContext.OnProcessEnded, TimeOut = TimeSpan.MaxValue, RedirectStandardInput = true }; var stoplogging = false; dosContext.Logger = message => { if (message != null) { var c = ipfsProcessContext.CheckLog(message); if (c == DosCancellation.Terminate) { dosContext.Cancelled = true; } if (c == DosCancellation.StopLogging || c == DosCancellation.Terminate) { stoplogging = true; } } if (!stoplogging && !string.IsNullOrEmpty(message)) { L.Info(message); } }; dosContext.ErrorLogger = error => { if (error != null) { var c = ipfsProcessContext.CheckError(error); if (c == DosCancellation.Terminate) { dosContext.Cancelled = true; } if (c == DosCancellation.StopLogging || c == DosCancellation.Terminate) { stoplogging = true; } if (error.Contains("prometheus collector", StringComparison.OrdinalIgnoreCase)) //Hack: When a repo is being initialised via the --init parameter, it spits out these ignorable error messages. { return; } if (error.Contains("mbinding.go:", StringComparison.OrdinalIgnoreCase)) //Hack: When a repo is being initialised via the --init parameter, it spits out these ignorable error messages. { return; } } if (!stoplogging && !string.IsNullOrEmpty(error)) { L.Error(error); } }; if (RedirectRepository) { dosContext.Environment.Add("IPFS_PATH", Instance.RepoDirectory.FullName); } // if (_dispatcher != null) // _dispatcher.Invoke(() => BindExit(dosContext)); //else //BindExit(dosContext); return(new ExecuteDos().CmdAsync(dosContext)); }
private void StartLocal(bool allowInitialisation = true) { _requiresInit = false; _lockWait = false; CurrentState = DaemonState.Starting; var processContext = new DosProcessContext("daemon --init --enable-pubsub-experiment", message => { if (message.Contains("Daemon is ready", StringComparison.OrdinalIgnoreCase)) { CurrentState = DaemonState.Running; } if (message.Contains("interrupt signal", StringComparison.OrdinalIgnoreCase)) { CurrentState = DaemonState.Stopping; return(DosCancellation.StopLogging); } return(DosCancellation.None); }, error => { if (error.Contains("'ipfs init'", StringComparison.OrdinalIgnoreCase) || error.Contains("no IPFS repo found", StringComparison.OrdinalIgnoreCase)) { _requiresInit = true; CurrentState = DaemonState.Stopped; return(DosCancellation.Terminate); } if (!error.Contains("already locked")) { return(DosCancellation.None); } _lockWait = true; CurrentState = DaemonState.Stopped; return(DosCancellation.Terminate); }, process => { _process = process; }) { OnProcessEnded = () => { CurrentState = DaemonState.Stopped; // if (AutoRestart && !_requiresInit && !_lockWait) // Start(); } }; var task = IssueIpfsNativeCommand(processContext); if (task == null) { CurrentState = DaemonState.Stopped; } task.ContinueWith(task1 => FinalStep(task1, allowInitialisation)); task.Start(); }