Skip to content

Commit

Permalink
Add sd-notify
Browse files Browse the repository at this point in the history
Currently, services dependent on aw-server.service (e.g. aw-awatcher)
start just after its launch.

This patch causes systemd to launch the dependent services only after
the rocket server is up an running.

It's aimed to help slow systems to not close the dependent service
prematurely due to not being able to connect to the server.
  • Loading branch information
wojnilowicz committed Jul 14, 2024
1 parent bb787fd commit 5031d85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions aw-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions aw-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ uuid = { version = "1.3", features = ["serde", "v4"] }
clap = { version = "4.1", features = ["derive", "cargo"] }
log-panics = { version = "2", features = ["with-backtrace"]}
rust-embed = { version = "8.0.0", features = ["interpolate-folder-path", "debug-embed"] }
sd-notify = "0.4.2"

aw-datastore = { path = "../aw-datastore" }
aw-models = { path = "../aw-models" }
Expand Down
8 changes: 6 additions & 2 deletions aw-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::path::PathBuf;
use clap::crate_version;
use clap::Parser;

use sd_notify::NotifyState;

use aw_server::*;

#[cfg(all(target_os = "linux", target_arch = "x86"))]
Expand Down Expand Up @@ -147,9 +149,11 @@ 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?;
let _ = sd_notify::notify(true, &[NotifyState::Ready]);
_rocket.launch().await?;

Ok(())
}

0 comments on commit 5031d85

Please sign in to comment.