feat: handle SIGTERM with graceful shutdown sequence - #298
Conversation
On Unix, register a SIGTERM handler that runs the existing handle_shutdown() cleanup (release power inhibitor, unmount all remotes, stop jobs/serves, shut down engine) before exiting. Previously SIGTERM (from systemd at OS shutdown/logout) killed the app abruptly without cleaning up FUSE mounts or releasing locks.
|
Hi @nvandamme, Thank you for opening this PR! Gracefully handling To keep the codebase modular and aligned with the rest of the project, could you please address the following points: 1. Move the signal listener from
|
|
will do! |
Per review feedback on PR Zarestia-Dev#298: - Move the SIGTERM listener out of lib.rs into core/event_listener.rs, where OS signals and background listeners are centralized - Merge it with handle_ctrl_c into handle_termination_signals using tokio::select! so both SIGINT and SIGTERM share one shutdown path - Both call shutdown_app(), which already runs the full graceful sequence (inhibitor release, unmounts, jobs/serves stop) + exit(0) Verified live: kill -TERM and kill -INT each trigger the unified handler, run the cleanup sequence, and exit cleanly.
Per review feedback on PR Zarestia-Dev#298: - Move the SIGTERM listener out of lib.rs into core/event_listener.rs, where OS signals and background listeners are centralized - Merge it with handle_ctrl_c into handle_termination_signals using tokio::select! so both SIGINT and SIGTERM share one shutdown path - Both call shutdown_app(), which already runs the full graceful sequence (inhibitor release, unmounts, jobs/serves stop) + exit(0) Verified live: kill -TERM and kill -INT each trigger the unified handler, run the cleanup sequence, and exit cleanly.
0f013fc to
ad41030
Compare
Problem
On Unix, when systemd sends SIGTERM to RClone Manager at OS shutdown or logout,
the process was killed abruptly without running its cleanup. This left FUSE
remotes mounted and the logind power-inhibitor lock held until the kernel tore
everything down, risking inconsistent remote state.
Fix
Register a SIGTERM handler (Unix only) that runs the existing
handle_shutdown()sequence before exiting — releasing the power inhibitor, unmounting all remotes,
stopping jobs/serves, and shutting down the engine. Each step already carries its
own timeout, so shutdown never stalls.
This reuses the same code path as a user-initiated quit (the
shutdown_appcommand),so behavior is consistent across exit triggers.
Verification
cargo fmt --check: cleancargo clippy --features desktop --no-default-features -- -D warnings: cleanunmounts kDrive, shuts down engine (PID), exits cleanly.