private static int InstallService(Conf conf) { ServiceController sc; if ((sc = SvcUtils.CreateSvc(conf)) == null) { Libs.Print($"Failed to install Service \"{conf.ServiceName}\""); return(1); } var ss = $"Installed Service \"{conf.ServiceName}\""; Libs.Print(ss); Log(ss, false); Log(""); var err = SvcUtils.SetSvcDescription(conf); if (err != null) { err = $"Failed to set description for Service \"{conf.ServiceName}\": {err}"; Libs.Print(err); Libs.Print("Please run `svc remove` to remove the Service"); Log(err); return(1); } return(StartService(sc)); }
private static int StopService(ServiceController sc) { if (sc.Status == ServiceControllerStatus.Stopped) { Libs.Print($"Service \"{sc.ServiceName}\" is already stopped"); return(1); } sc.StopSvc(); Libs.Print($"Stopped Service \"{sc.ServiceName}\""); return(0); }
private static int CreateProject(string name) { var err = Libs.CopyDir($"{Libs.BinDir}..\\samples\\csharp-version", name, ".log"); if (err != null) { Libs.Print(err); return(1); } Libs.Print($"Create an Easy-Service project in {name}"); return(0); }
private static int StartService(ServiceController sc) { if (sc.Status == ServiceControllerStatus.Running) { Libs.Print($"Service \"{sc.ServiceName}\" is already started"); return(1); } Console.Write($"Starting..."); Libs.NewThread(Waiting); sc.StartSvc(); Libs.Print($"\nStarted Service \"{sc.ServiceName}\""); return(0); }
private static int StartService(ServiceController sc) { if (sc.Status == ServiceControllerStatus.Running) { Libs.Print($"Service \"{sc.ServiceName}\" is already started"); return(1); } var errInfo = "Failed to start the service, please refer to svc.log to see what happened"; Libs.NewThread(() => Waiting("Start", errInfo)); sc.StartSvc(); Libs.Print($"Started Service \"{sc.ServiceName}\""); return(0); }
private static int RemoveService(ServiceController sc) { StopService(sc); if (!SvcUtils.DeleteSvc(conf.ServiceName)) { Libs.Print($"Failed to remove Service \"{conf.ServiceName}\""); return(1); } var ss = $"Removed Service \"{conf.ServiceName}\""; Log(""); Log(ss); Libs.Print(ss); return(0); }
public void ShowConfig() { Libs.Print($"ServiceName: {ServiceName}"); Libs.Print($"DisplayName: {DisplayName}"); Libs.Print($"Description: {Description}"); Libs.Print($"Worker: {Worker}"); Libs.Print($"Worker's fileName: {WorkerFileName}"); Libs.Print($"Worker's arguments: {WorkerArguments}"); Libs.Print($"WorkingDir: {WorkingDir}"); Libs.Print($"OutFileDir: {OutFileDir}"); Libs.Print($"WaitSecondsForWorkerToExit: {WaitSecondsForWorkerToExit}"); Libs.Print($"WorkerEncoding: {WorkerEncoding}"); Libs.Print($"Domain: {Domain}"); Libs.Print($"User: {User}"); Libs.Print($"Password: {Password}"); }
public static int Main(string[] args) { if (args.Length == 0) { ServiceBase.Run(new SimpleService()); return(0); } string op = args[0]; if (op == "version" || op == "--version" || op == "-v") { Libs.Print(VERSION); return(0); } if (!COMMANDS.Split('|').Contains(op) || (op == "create" && args.Length < 2)) { Libs.Print(USAGE); return(1); } if (op == "create") { return(CreateProject(args[1])); } var err = conf.Read(); if (err != null) { Libs.Print($"Configuration Error:\n{err}"); return(1); } if (op == "test-worker") { return(TestWorker()); } var sc = SvcUtils.GetServiceController(conf.ServiceName); var status = (sc == null) ? "not installed" : sc.Status.ToString().ToLower(); if (op == "check" || op == "status") { conf.ShowConfig(); Libs.Print($"\nService status: {status}"); return(0); } if (op == "install") { if (sc != null) { Libs.Print($"Service \"{conf.ServiceName}\" is already installed!"); return(1); } return(InstallService(conf)); } if (sc == null) { Libs.Print($"Service \"{conf.ServiceName}\" is not installed!"); return(1); } if (op == "start") { return(StartService(sc)); } if (op == "stop") { return(StopService(sc)); } if (op == "restart") { StopService(sc); return(StartService(sc)); } // op == "remove" return(RemoveService(sc)); }