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 7533002
Show file tree
Hide file tree
Showing 3 changed files with 12 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
3 changes: 3 additions & 0 deletions aw-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 7 additions & 2 deletions aw-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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(())
}

0 comments on commit 7533002

Please sign in to comment.