What is the proper way to start a Rust program on FreeBSD?

I'm trying to get a Rust program to start automatically on FreeBSD using the rc.d system.

I have a script like this:

Code:
#!/bin/sh

. /etc/rc.subr

name=rustapps
rcvar=rustapps_enable

start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name
: ${rustapps_enable:=no}
: ${rustapps_msg="Nothing started."}

rustapps_start()
{

    /root/.cargo/bin/cargo run --manifest-path /usr/local/rustapps/hello_server/Cargo.toml &

}

run_rc_command "$1"

When I execute it, I get this error:

root@freebsd:/usr/local/etc/rc.d # error: no default toolchain configured

However, I have no problem when I execute the line (/root/.cargo/bin/cargo run --manifest-path /usr/local/rustapps/hello_server/Cargo.toml &) to start it.

Therefore, what is the proper way to get a Rust program started automatically on FreeBSD?

If I would manually execute:
# cd /usr/local/rustapps/hello_server
# cargo run
it would just work because the environment variables are set and the "cargo run" comand works inside the compiled application's directory. However, I can't do a "cd" command within a rc.d script and I'm not sure how to set the environment variables that the cargo command needs. Please help.
 
Back
Top