From ceeff5f76c69d98319bb3fb7f7779b6046478d6b Mon Sep 17 00:00:00 2001 From: Alexander Petric Date: Mon, 17 Nov 2025 06:48:31 -0500 Subject: [PATCH] feat: support to run windows binary as service (#7153) * feat: support to run windows binary as service * ee ref * ee ref * flags * Update backend/src/main.rs Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> * fix ai commit * fix * ee ref --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Ruben Fiszel --- backend/Cargo.lock | 13 +++++++++++++ backend/Cargo.toml | 4 ++++ backend/ee-repo-ref.txt | 2 +- backend/src/main.rs | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 629070a7fa..7bd5cf2334 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -15204,6 +15204,8 @@ dependencies = [ "windmill-indexer", "windmill-queue", "windmill-worker", + "windows-service", + "windows-sys 0.52.0", ] [[package]] @@ -16089,6 +16091,17 @@ dependencies = [ "windows-link 0.2.1", ] +[[package]] +name = "windows-service" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24d6bcc7f734a4091ecf8d7a64c5f7d7066f45585c1861eba06449909609c8a" +dependencies = [ + "bitflags 2.9.4", + "widestring", + "windows-sys 0.52.0", +] + [[package]] name = "windows-strings" version = "0.4.2" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index dd68fe3e9d..15377a4a23 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -161,6 +161,10 @@ nom.workspace = true globset.workspace = true +[target.'cfg(windows)'.dependencies] +windows-service = "0.7" +windows-sys = { version = "0.52", features = ["Win32_System_Services", "Win32_System_Console", "Win32_Foundation"] } + [target.'cfg(not(target_env = "msvc"))'.dependencies] tikv-jemallocator = { optional = true, workspace = true } tikv-jemalloc-sys = { optional = true, workspace = true } diff --git a/backend/ee-repo-ref.txt b/backend/ee-repo-ref.txt index 7d5311398e..beac4ec475 100644 --- a/backend/ee-repo-ref.txt +++ b/backend/ee-repo-ref.txt @@ -1 +1 @@ -423c3c2d175b15b7c0f010e08f1848a7710e31be \ No newline at end of file +41e693c08aa096a0d2e9a76a4ebe9b4149bdde24 \ No newline at end of file diff --git a/backend/src/main.rs b/backend/src/main.rs index 70f428d4ca..26e1755fea 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -113,6 +113,10 @@ pub mod ee; mod ee_oss; mod monitor; +// Windows service support - EE feature +#[cfg(all(windows, feature = "enterprise", feature = "private"))] +mod windows_service_ee; + pub fn setup_deno_runtime() -> anyhow::Result<()> { // https://github.com/denoland/deno/blob/main/cli/main.rs#L477 #[cfg(feature = "deno_core")] @@ -207,6 +211,17 @@ lazy_static::lazy_static! { } pub fn main() -> anyhow::Result<()> { + // On Windows with enterprise feature, check if running as a service + #[cfg(all(windows, feature = "enterprise", feature = "private"))] + { + if windows_service_ee::is_running_as_service() { + // Run as Windows service with SCM handlers + return windows_service_ee::run_as_windows_service() + .map_err(|e| anyhow::anyhow!("Failed to run as Windows service: {}", e)); + } + } + + // Normal execution (console/foreground mode) setup_deno_runtime()?; create_and_run_current_thread_inner(windmill_main()) }