From 657049832be985a7f8d48f1135aaf58a7eb3c9e7 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Tue, 19 Jul 2022 02:47:41 +0200 Subject: [PATCH] refactor(windows): `windows-service` option support via config file --- src/settings/cli.rs | 2 +- src/settings/file.rs | 3 +++ src/settings/mod.rs | 13 +++++++++++-- src/winservice.rs | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/settings/cli.rs b/src/settings/cli.rs index f062165..abb83fc 100644 --- a/src/settings/cli.rs +++ b/src/settings/cli.rs @@ -190,7 +190,7 @@ pub struct General { default_value = "false", env = "SERVER_WINDOWS_SERVICE" )] - /// Run the web server as a Windows Service. + /// Tell the web server to run in a Windows Service context. Note that the `install` subcommand will enable this option automatically. pub windows_service: bool, // Windows commands diff --git a/src/settings/file.rs b/src/settings/file.rs index f2bcedf..fc74816 100644 --- a/src/settings/file.rs +++ b/src/settings/file.rs @@ -127,6 +127,9 @@ pub struct General { pub page_fallback: Option, pub log_remote_address: Option, + + #[cfg(windows)] + pub windows_service: Option, } /// Full server configuration diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 45faf46..77cbfca 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -84,6 +84,10 @@ impl Settings { let mut page_fallback = opts.page_fallback; let mut log_remote_address = opts.log_remote_address; + // Windows-only options + #[cfg(windows)] + let mut windows_service = opts.windows_service; + // Define the advanced file options let mut settings_advanced: Option = None; @@ -170,6 +174,12 @@ impl Settings { if let Some(v) = general.log_remote_address { log_remote_address = v } + + // Windows-only options + #[cfg(windows)] + if let Some(v) = general.windows_service { + windows_service = v + } } // File-based "advanced" options @@ -291,10 +301,9 @@ impl Settings { page_fallback, log_remote_address, - // NOTE: // Windows-only options and commands #[cfg(windows)] - windows_service: opts.windows_service, + windows_service, #[cfg(windows)] commands: opts.commands, }, diff --git a/src/winservice.rs b/src/winservice.rs index 2a81207..cb943c0 100644 --- a/src/winservice.rs +++ b/src/winservice.rs @@ -1,4 +1,4 @@ -// Module that lets SWS to run as a "Windows Service" +//! Module that lets SWS to run in a "Windows Service" context use std::ffi::OsString; use std::thread; -- libgit2 1.7.2