Running a Rust program as a systemd service

Anyone got best-practice examples of:

(a) how to run Rust programs as a systemd service

(b) how to ship systemd unit files and associated configurations in a sensible manner, especially if you also want the program available as a cargo crate via cargo install?

1 Like

Rust programs are just binaries. What works for C or Go should work for Rust.

Here is a tutorial on how to run a Go program with systemd. Rust should be the same:

Don't use cargo install. It's unable to track what files have been created on installation, so cargo uninstall will only remove the main executable, and leave behind junk systemd config.

You can use cargo-deb to make a proper installable package.


Yeah, I suspected there's no good way to do that using cargo install. I do still want to publish it as a crate and will still recommend cargo install for people who want to use it without systemd.

1 Like