From f2ff5f0d6ec957509a511aef716fc907671418f0 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Mon, 23 May 2022 14:03:28 +0200 Subject: [PATCH] refactor: short windows service argument and clarify commands output --- src/bin/server.rs | 2 +- src/settings/cli.rs | 4 ++-- src/settings/mod.rs | 4 ++-- src/winservice.rs | 11 ++++++----- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index 0cf9154..4d7732c 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -26,7 +26,7 @@ fn main() -> Result { return winservice::uninstall_service(); } } - } else if opts.general.as_windows_service { + } else if opts.general.windows_service { return winservice::run_server_as_service(); } } diff --git a/src/settings/cli.rs b/src/settings/cli.rs index eb2afb6..9f2a033 100644 --- a/src/settings/cli.rs +++ b/src/settings/cli.rs @@ -179,10 +179,10 @@ pub struct General { short = "s", parse(try_from_str), default_value = "false", - env = "SERVER_AS_WINDOWS_SERVICE" + env = "SERVER_WINDOWS_SERVICE" )] /// Run the web server as a Windows Service. - pub as_windows_service: bool, + pub windows_service: bool, // Windows commands #[cfg(windows)] diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 0540ad7..dcb3707 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -207,10 +207,10 @@ impl Settings { grace_period, page_fallback, - // NOTE + // NOTE: // Windows-only options and commands #[cfg(windows)] - as_windows_service: opts.as_windows_service, + windows_service: opts.windows_service, #[cfg(windows)] commands: opts.commands, }, diff --git a/src/winservice.rs b/src/winservice.rs index 805187b..27a40ba 100644 --- a/src/winservice.rs +++ b/src/winservice.rs @@ -185,7 +185,7 @@ pub fn install_service(config_file: Option) -> Result { let service_binary_path = std::env::current_exe().unwrap().with_file_name(SERVICE_EXE); // Set service binary default arguments - let mut service_binary_arguments = vec![OsString::from("--as-windows-service=true")]; + let mut service_binary_arguments = vec![OsString::from("--windows-service=true")]; // Append a `--config-file` path to the binary arguments if present if let Some(f) = config_file { @@ -216,6 +216,10 @@ pub fn install_service(config_file: Option) -> Result { "Windows Service ({}) is installed successfully!", SERVICE_NAME ); + println!( + "Start the service typing: sc.exe start \"{}\" (it requires administrator privileges) or using the 'services.msc' application.", + SERVICE_NAME + ); Ok(()) } @@ -237,10 +241,7 @@ pub fn uninstall_service() -> Result { service.delete()?; - println!( - "Windows Service ({}) uninstalled successfully!", - SERVICE_NAME - ); + println!("Windows Service ({}) is uninstalled!", SERVICE_NAME); Ok(()) } -- libgit2 1.7.2