How to set systemd and let rust run in background?

Hi everyone,i tried different ways to have systemd call rust to run in the background, but none of them succeeded.

Let systemd call the shell to execute the cargo run: the error is that it reads only ‘‘cargo’’, but treats ‘run’ as another parameter, so it won’t run.

Use cargo-deb and call it: the error is thread 'main' panicked at called Option::unwrap() on a None value, src/libcore/option.rs:355:21 and note: Run with RUST_BACKTRACE=1 for a backtrace.

Is there any better way?

Note: I use iron to set up a web service, enter url to execute cassandra’s query

You just need to point the service file at the compiled binary, not cargo. cargo run tells you the pathname.

Yes, I have set the location of the compiled binary, but the problem is still the error described in the second.

The following is the file content of systemd(ExecStart is a binary file):

[Unit]
Description=cassandra-rs-driver
After=network.target

[Service]
User=root
ExecStart=/usr/bin/cassandra-rs-driver

[Install]
WantedBy=multi-user.target

The second error tells you it is running your binary but there’s a bug. You’re unwrapping something that is None.

4 Likes

I found the problem, it is about the use of CombinedLogger. So, I have to find a new log lib to replace it.