How to pass environment variables with FreeBSD service command?

How to pass environment variables with FreeBSD service command?

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:

관련 정보