diff --git a/README.md b/README.md index b1497bf..34bfc94 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,22 @@ Placeholders in `command` / `stop_command`: `{name}`, `{workdir}`, `{pid}`, `{lo See `config.example.toml` for a full example. +## systemd (user mode) + +```sh +mkdir -p ~/.config/systemd/user +cp contrib/rss.service ~/.config/systemd/user/ +systemctl --user daemon-reload +systemctl --user enable rss +systemctl --user start rss +``` + +Requires `linger` for headless users: + +```sh +sudo loginctl enable-linger $USER +``` + ## Install ```sh diff --git a/contrib/rss.service b/contrib/rss.service new file mode 100644 index 0000000..721f491 --- /dev/null +++ b/contrib/rss.service @@ -0,0 +1,13 @@ +[Unit] +Description=RuSt Supervisor +After=network.target + +[Service] +Type=simple +ExecStart=%h/.cargo/bin/rss daemon +Restart=on-failure +RestartSec=5 +Environment=RSS_CONFIG=%h/.config/rss/config.toml + +[Install] +WantedBy=default.target diff --git a/src/config.rs b/src/config.rs index c3fdd4d..9db862b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -55,6 +55,8 @@ fn default_stop_signal() -> String { pub enum RestartPolicy { No, Always, + #[serde(alias = "unless-stopped")] + UnlessStopped, OnFailure, } diff --git a/src/supervisor.rs b/src/supervisor.rs index 6f6820c..fca1674 100644 --- a/src/supervisor.rs +++ b/src/supervisor.rs @@ -77,7 +77,7 @@ pub fn run_supervisor(name: &str, cfg: &ServiceConfig) { let should_restart = match cfg.restart { RestartPolicy::No => false, - RestartPolicy::Always => true, + RestartPolicy::Always | RestartPolicy::UnlessStopped => true, RestartPolicy::OnFailure => !status.success(), };