Skip to content

Commit d2d463c

Browse files
shaoweihuclaude
andcommitted
fix(service_manager): systemd unit Restart=on-failure → always
After `gateway_auto_update::tick` completes a binary swap it calls `std::process::exit(0)` to hand off to the supervisor (per the doc at gateway_auto_update.rs:18 — "the OS supervisor … systemd Restart=always — relaunches us on the new binary"). The systemd unit template shipped `Restart=on-failure`, which systemd treats as success-and-stop for an exit-code-0 process. So after every gateway self-update on Linux, systemd correctly noticed the process exited cleanly and refused to restart it — silently turning auto-update into "the gateway uninstalls itself". macOS launchd defaults to `KeepAlive=true` so the symmetric bug was Linux-only. 0.1.25 was published briefly with this defect and pulled once it was caught; this rolls forward into 0.1.26. Added a unit test asserting the rendered unit contains `Restart=always` and does not contain `Restart=on-failure`, so this can't silently regress in a future template tweak. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1eab39d commit d2d463c

4 files changed

Lines changed: 20 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ members = [
1414
resolver = "2"
1515

1616
[workspace.package]
17-
version = "0.1.25"
17+
version = "0.1.26"
1818
edition = "2024"
1919
license = "MIT"
2020
repository = "https://github.com/Pyiner/garyx"

garyx/src/service_manager/systemd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ Wants=network-online.target
271271
[Service]
272272
Type=simple
273273
ExecStart=/bin/sh -c 'exec \"$(getent passwd %u | cut -d: -f7)\" -lic \"exec {binary_arg} gateway run --host {host} --port {port}\"'
274-
Restart=on-failure
274+
Restart=always
275275
RestartSec=5
276276
TimeoutStopSec=10
277277
{workspace_line}EnvironmentFile=-{env_file}

garyx/src/service_manager/systemd/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ fn render_unit_file_contains_exec_start_and_logs() {
2020
assert!(unit.contains("TimeoutStopSec=10"));
2121
assert!(unit.contains("WantedBy=default.target"));
2222
assert!(!unit.contains("GARYX_WORKSPACE_ROOT"));
23+
24+
// `gateway_auto_update::tick` ends every successful binary swap with
25+
// `std::process::exit(0)` and relies on the supervisor relaunching the
26+
// process on the new binary. systemd treats exit-code-0 as success, so
27+
// `Restart=on-failure` would silently kill the service after self-update.
28+
// The unit MUST use `Restart=always` to make exit-code-0 trigger a restart.
29+
assert!(unit.contains("Restart=always"));
30+
assert!(!unit.contains("Restart=on-failure"));
2331
}
2432

2533
#[test]

0 commit comments

Comments
 (0)