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?
I actually find it a bit strange to use the cargo command to start a Rust program. Can it be compile into a full-standalone executable?
Anyway, for now, I just need my problem solved - to get it started automatically on FreeBSD. Please help. Thanks!
Building a stand-alone executable is definitely preferred. In hello_server, run cargo build —release, and then check the hello_server/target/release/ directory for the executable (maybe it will be hello_server in your case). Then you can reference the executable in your startup script.
Yup, your suggestion worked! (I had been too engrossed in development mode and didn't know by simply using the "--release" flag, cargo will build a standalone executable.
As further info, the --release flag tells cargo to compile using the "release profile". You can customize this using directives in your crate's Cargo.toml file.
I'm having another problem after resolving this. I've posted another topic: Release build is unable to read .env variables I got it started automatically from FreeBSD's rc.d system, but it is unable to read the .env file to access the database. The preferred solution is not to set any hard links/location within the project. How can I resolve it?