public DaemonProcess ToDaemonProcess(string workingDirectory) { DaemonProcess process = ToDaemonProcess(); process.FileName = Path.Combine(workingDirectory, FileName); process.WorkingDirectory = workingDirectory; return(process); }
public static DaemonProcessMonitor Start(DaemonProcess process, ILogger logger = null) { logger = logger ?? Log.Default; logger.AddEntry("Monitoring {0}", process.Name); DaemonProcessMonitor result = new DaemonProcessMonitor(process, logger); process.StandardOut += (o, a) => logger.Info(((DaemonProcessEventArgs)a).Message); process.ErrorOut += (o, a) => logger.Warning(((DaemonProcessEventArgs)a).Message); process.Start(result.TryRestart); return(result); }
private void StartProcess(DaemonProcess process) { try { string key = process.ToString(); Logger.AddEntry("Starting {0}", key); process.Subscribe(Logger); _monitors.Add(key, DaemonProcessMonitor.Start(process)); } catch (Exception ex) { Logger.AddEntry("Error starting process {0}: {1}", ex, process?.ToString(), ex.Message); } }
public DaemonProcessMonitor(DaemonProcess process, ILogger logger = null) { Logger = logger ?? Log.Default; MaxLogSizeInBytes = 1048576; Process = process; FlushLineCount = 25; FlushTimeout = 5000; OutLogName = Path.Combine(ServiceConfig.LogRoot, $"{Process.Name}_out.txt"); ErrorLogName = Path.Combine(ServiceConfig.LogRoot, $"{Process.Name}_err.txt"); Logger.AddEntry("Outlog for {0} is {1}", Process.Name, OutLogName); Logger.AddEntry("ErrorLog for {0} is {1}", Process.Name, ErrorLogName); StandardOutLog = new FileInfo(OutLogName); ErrorOutLog = new FileInfo(ErrorLogName); StartTimedFlush(); }
public virtual CoreServiceResponse AddProcess(DaemonProcessInfo processInfo) { try { DaemonProcess process = processInfo.CopyAs <DaemonProcess>(); List <DaemonProcess> current = new List <DaemonProcess>(Processes) { process }; Processes = current.ToArray(); Processes.ToJsonFile(ConfigFile); StartProcess(process); return(new CoreServiceResponse { Success = true }); } catch (Exception ex) { return(new CoreServiceResponse { Success = false, Message = ex.Message }); } }