diff --git a/aw-server.service b/aw-server.service index 75b53021..24ab545b 100644 --- a/aw-server.service +++ b/aw-server.service @@ -14,12 +14,12 @@ # [Service] -Type=simple +Type=notify ExecStart=aw-server [Unit] Description=ActivityWatch Server (Rust implementation) -Wants=network.target +After=network.target [Install] WantedBy=default.target diff --git a/aw-server/Cargo.toml b/aw-server/Cargo.toml index ea70b851..56c407e4 100644 --- a/aw-server/Cargo.toml +++ b/aw-server/Cargo.toml @@ -35,6 +35,9 @@ aw-models = { path = "../aw-models" } aw-transform = { path = "../aw-transform" } aw-query = { path = "../aw-query" } +[target.'cfg(target_os="linux")'.dependencies] +sd-notify = "0.4.2" + [target.'cfg(all(target_os="linux", target_arch="x86"))'.dependencies] jemallocator = "0.5.0" diff --git a/aw-server/src/main.rs b/aw-server/src/main.rs index 933366e6..2cbf39e7 100644 --- a/aw-server/src/main.rs +++ b/aw-server/src/main.rs @@ -9,6 +9,8 @@ use clap::Parser; use aw_server::*; +#[cfg(target_os = "linux")] +use sd_notify::NotifyState; #[cfg(all(target_os = "linux", target_arch = "x86"))] extern crate jemallocator; #[cfg(all(target_os = "linux", target_arch = "x86"))] @@ -147,9 +149,12 @@ async fn main() -> Result<(), rocket::Error> { device_id, }; - let _ = endpoints::build_rocket(server_state, config) - .launch() + let _rocket = endpoints::build_rocket(server_state, config) + .ignite() .await?; + #[cfg(target_os = "linux")] + let _ = sd_notify::notify(true, &[NotifyState::Ready]); + _rocket.launch().await?; Ok(()) }