The rc.subr ${name}_env
specifies this for setting environment variable:
${name}_env A list of environment variables to run command
with. This will be passed as arguments to
env(1) utility.
So I tried using it like these methods, via my rc.conf for my daemon named /etc/rc.d/mydaemon
.
in /etc/rc.conf
:
mydaemon_env="MYD_ROOT"
This give error on starting:
# root @ rahul in /etc/rc.d [10:52:49]
$ service mydaemon onestart
Starting mydaemon.
env: MYD_ROOT: No such file or directory
/etc/rc.d/mydaemon: WARNING: failed to start mydaemon
Could someone help out on what I am missing?
답변1
It is supposed to be in format NAME=VALUE
.
mydaemon_env="MYD_ROOT=value"
답변2
A new flag has recently been added to the service
command. With the -E
flag, it is now possible to set the environment variables when starting a daemon with the service
command. The new flag will be available in FreeBSD 14.0 and later. As of 2023-09-04, it has not been merged back into older stable branches.
Some references:
- The commit introducing the
-E
flag: https://cgit.freebsd.org/src/commit/usr.sbin/service/service.sh?id=194e059bb80334e6f4f791a186015b20d7f6f4b8