Release build is unable to read .env variables

I had a problem about deploying to FreeBSD earlier and was resolved.

This time, I have an executable built by issuing "cargo build --release".

If I execute it on the directory location at ..."target/release" by issuing "./hello_server" or "./hello_server &" it ran without any problem.

However, when I try to start it using FreeBSD's rc.d system using the script below:


. /etc/rc.subr



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

/usr/local/rustapps/hello_server/target/release/hello_server &

run_rc_command "$1"

It presented me with "DATABASE_URL must be set: NotPresent" panic. Clearly, it is not reading the .env variables.

How can I resolve this problem? I need the app to start using FreeBSD rc.d script. Thanks!

For me it seems as if the aren't yet set by the OS (however I have no experience with FreeBSD)

I did further research and discovered that the dotenv package is meant to be used for development and testing. So, therefore, what is the best practice to set configuration/environment variables for a Rust application?

.env is a user login source rather than for daemons.
Matching the OS is one approach. On *nix is typically a file in some etc directory.
Quick search gives;

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.