public ServiceStatus GetServiceStatus() { try { using (var proc = new ShellExe().RunBinFile("ps", "auxf")) { var output = proc.StandardOutput.ReadToEnd(); var error = proc.StandardError.ReadToEnd(); log.DebugFormat("GetMonoServiceStatus, processName = {0}", serviceNameString); if (!string.IsNullOrWhiteSpace(error)) { log.ErrorFormat("GetMonoServiceStatus. Unexpected error: {0}, serviceStatus = {1}", error, ServiceStatus.NotFound); return(ServiceStatus.NotFound); } if (output.Contains(string.Format("-l:/tmp/{0}", serviceNameString))) { log.DebugFormat("GetMonoServiceStatus, serviceName = {0}, serviceStatus = {1}", serviceNameString, ServiceStatus.Running); return(ServiceStatus.Running); } log.DebugFormat("GetMonoServiceStatus, serviceName: {0}, serviceStatus = {1}", serviceNameString, ServiceStatus.Stopped); return(ServiceStatus.Stopped); } } catch (Exception ex) { log.ErrorFormat("GetMonoServiceStatus. Unexpected error. ProcessName = {0}, serviceStatus = {1}, ex = {2}", serviceNameString, ServiceStatus.NotFound, ex.ToString()); return(ServiceStatus.NotFound); } }
private string Run(string command, string errorResult) { try { using (var proc = new ShellExe().RunBinFile("sudo", string.Format("service {0} {1}", serviceNameString, command))) { var output = proc.StandardOutput.ReadToEnd(); var error = proc.StandardError.ReadToEnd(); if (!string.IsNullOrWhiteSpace(error)) { log.ErrorFormat("{0}MonoService. Unexpected error: serviceName = {1}, error = {2}, output: {3}", command, serviceNameString, error, output); return(errorResult); } return(string.Empty); } } catch (Exception ex) { log.ErrorFormat("{0}MonoService. Unexpected error. ProcessName = {1}, ex = {2}", command, serviceNameString, ex.ToString()); return(errorResult); } }
public static void RunShellOverloaderExe(string[] args, object osObj, Computer target) { OS os = (OS)osObj; bool flag1 = false; bool flag2 = false; bool flag3 = false; if (args.Length > 1) { if (args[1].ToLower() == "-c") { flag1 = false; flag2 = false; flag3 = true; } else if (args[1].ToLower() == "-o") { flag1 = false; flag2 = true; } else if (args[1].ToLower() == "-e") { flag1 = true; flag2 = false; flag3 = false; } } if (!flag2 && !flag1 && !flag3) { os.write("--------------------------------------"); os.write("ConShell " + LocaleTerms.Loc("ERROR: Not enough arguments!")); os.write(LocaleTerms.Loc("Usage:") + " ConShell [-" + LocaleTerms.Loc("option") + "]"); os.write(LocaleTerms.Loc("Valid Options:") + " [-e (" + LocaleTerms.Loc("Exit") + ")] [-o (" + LocaleTerms.Loc("Overload") + ")] [-c (" + LocaleTerms.Loc("Cancel Overload") + ")]"); os.write("--------------------------------------"); } else if (os.exes.Count <= 0) { os.write("--------------------------------------"); os.write("ConShell " + LocaleTerms.Loc("ERROR: No active shells")); os.write("--------------------------------------"); } else { for (int index = 0; index < os.exes.Count; ++index) { ShellExe ex = os.exes[index] as ShellExe; if (ex != null) { if (flag1) { ex.Completed(); } else if (flag3) { ex.cancelTarget(); } else if (flag2) { ex.StartOverload(); } } } } }