index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2022-07-19 0:47:41.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2022-07-19 0:47:41.0 +00:00:00
commit
657049832be985a7f8d48f1135aaf58a7eb3c9e7 [patch]
tree
faa932eb1750abcb001ea3ba9fea16a39470a69c
parent
e4228af63064281172c93cf7de0f82f935404eff
download
657049832be985a7f8d48f1135aaf58a7eb3c9e7.tar.gz

refactor(windows): `windows-service` option support via config file



Diff

 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<PathBuf>,

    pub log_remote_address: Option<bool>,

    #[cfg(windows)]
    pub windows_service: Option<bool>,
}

/// 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<Advanced> = 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;