private static void ConfigureWindowsServiceCommand() { const string defaultServiceName = "RavenDB"; if (PlatformDetails.RunningOnPosix) { return; } _app.Command("windows-service", cmd => { cmd.Description = "Allows to perform an operation on RavenDB Server run as Windows Service"; cmd.HelpOption(HelpOptionString); ConfigureServiceNameOption(cmd); cmd.Command("register", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); var serverDirOpt = ConfigureServerDirOption(subcmd); subcmd.Description = "Registers RavenDB Server as Windows Service"; subcmd.ExtendedHelpText = "\r\nRegisters RavenDB Server as Windows Service. Any additional arguments passed after command options are going to be passed to the server."; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Register( serviceNameOpt.Value() ?? defaultServiceName, serverDirOpt.Value(), subcmd.RemainingArguments); return(0); }); }, throwOnUnexpectedArg: false); cmd.Command("unregister", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.ExtendedHelpText = subcmd.Description = "Unregisters RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Unregister(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.Command("start", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.Description = "Starts RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Start(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.Command("stop", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.ExtendedHelpText = subcmd.Description = "Stops RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Stop(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.OnExecute(() => { cmd.ShowHelp(); return(1); }); }); }
private static void ConfigureWindowsServiceCommand() { const string defaultServiceName = "RavenDB"; if (PlatformDetails.RunningOnPosix) { return; } _app.Command("windows-service", cmd => { var serviceString = PlatformDetails.RunningOnPosix ? "daemon" : "Windows Service"; cmd.Description = $"Allows to perform an operation on RavenDB Server which is running as {serviceString}"; cmd.HelpOption(HelpOptionString); ConfigureServiceNameOption(cmd); cmd.Command("register", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); var serviceUserNameOpt = ConfigureServiceUserNameOption(subcmd); var serviceUserPasswordOpt = ConfigureServiceUserPasswordOption(subcmd); var serverDirOpt = ConfigureServerDirOption(subcmd); subcmd.Description = "Registers RavenDB Server as Windows Service"; subcmd.ExtendedHelpText = Environment.NewLine + "Registers RavenDB Server as Windows Service. " + "Any additional arguments passed after command options are going to be passed to the server."; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Register( serviceNameOpt.Value() ?? defaultServiceName, serviceUserNameOpt.Value(), serviceUserPasswordOpt.Value(), serverDirOpt.Value(), subcmd.RemainingArguments); return(0); }); subcmd.UnrecognizedArgumentHandling = UnrecognizedArgumentHandling.StopParsingAndCollect; }); cmd.Command("unregister", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.ExtendedHelpText = subcmd.Description = "Unregisters RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Unregister(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.Command("start", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.Description = "Starts RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Start(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.Command("stop", subcmd => { var serviceNameOpt = ConfigureServiceNameOption(subcmd); subcmd.ExtendedHelpText = subcmd.Description = "Stops RavenDB Server Windows Service"; subcmd.HelpOption(HelpOptionString); subcmd.OnExecute(() => { WindowsService.Stop(serviceNameOpt.Value() ?? defaultServiceName); return(0); }); }); cmd.OnExecute(() => { cmd.ShowHelp(); return(1); }); }); }