Skip to content

Commit 8d7ce89

Browse files
authored
fix(linux): add sd-notify for better systemd interop (#489)
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.
1 parent bb787fd commit 8d7ce89

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Diff for: aw-server.service

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#
1515

1616
[Service]
17-
Type=simple
17+
Type=notify
1818
ExecStart=aw-server
1919

2020
[Unit]
2121
Description=ActivityWatch Server (Rust implementation)
22-
Wants=network.target
22+
After=network.target
2323

2424
[Install]
2525
WantedBy=default.target

Diff for: aw-server/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ aw-models = { path = "../aw-models" }
3535
aw-transform = { path = "../aw-transform" }
3636
aw-query = { path = "../aw-query" }
3737

38+
[target.'cfg(target_os="linux")'.dependencies]
39+
sd-notify = "0.4.2"
40+
3841
[target.'cfg(all(target_os="linux", target_arch="x86"))'.dependencies]
3942
jemallocator = "0.5.0"
4043

Diff for: aw-server/src/main.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use clap::Parser;
99

1010
use aw_server::*;
1111

12+
#[cfg(target_os = "linux")]
13+
use sd_notify::NotifyState;
1214
#[cfg(all(target_os = "linux", target_arch = "x86"))]
1315
extern crate jemallocator;
1416
#[cfg(all(target_os = "linux", target_arch = "x86"))]
@@ -147,9 +149,12 @@ async fn main() -> Result<(), rocket::Error> {
147149
device_id,
148150
};
149151

150-
let _ = endpoints::build_rocket(server_state, config)
151-
.launch()
152+
let _rocket = endpoints::build_rocket(server_state, config)
153+
.ignite()
152154
.await?;
155+
#[cfg(target_os = "linux")]
156+
let _ = sd_notify::notify(true, &[NotifyState::Ready]);
157+
_rocket.launch().await?;
153158

154159
Ok(())
155160
}

0 commit comments

Comments
 (0)