Prev: Next: Up: Top[Contents][Index]


6 Environment Variables

Several most often used options have corresponding environment variables. If given the --env option, genrc will consult them, if the corresponding option was not supplied.

Don’t forget to export these environment variables before invoking genrc.

The list of environment variables and corresponding command line options follows:

VariableOption
GENRC_COMMAND=command--command=command
GENRC_CREATE_PIDFILE=name--create-pidfile=name
GENRC_GROUP=groups--group=groups
GENRC_KILL_MODE=mode--kill-mode=mode
GENRC_LOG_ERR_FILE=file--log-err-file=file
GENRC_LOG_FACILITY=name--log-facility=name
GENRC_LOG_FILE=file--log-file=file
GENRC_LOG_OUT_FILE=file--log-out-file=file
GENRC_LOG_TAG=str--log-tag=str
GENRC_PID_FROM=source--pid-from=source
GENRC_PROGRAM=name--program=name
GENRC_SENTINEL=1--sentinel
GENRC_SIGNAL_RELOAD=sig--signal-reload=sig
GENRC_SIGNAL_STOP=sig--signal-stop=sig
GENRC_TIMEOUT=seconds--timeout=seconds
GENRC_USER=name--user=name

It was supposed that the use of environment options might improve readability of startup scripts. For instance, the example script from the first chapter can be rewritten as follows:

#! /bin/sh
PIDFILE=/var/run/ntpd.pid
export GENRC_COMMAND="/usr/sbin/ntpd -g -p $PIDFILE"
export GENRC_PID_FROM="FILE:$PIDFILE"
exec /sbin/genrc --env --no-reload --signal-stop=SIGHUP "$@"

However, it was soon found out that relying on the environment can also lead to some hard-to-diagnose failures. Suppose, for example, that you set GENRC_USER=nobody to experiment with some program. When done, you forget to unset it and restart ntpd, using the script above. As a result, ntpd will start with the privileges of user ‘nobody’ and fail, consequently.

The use of the explicit option --env is supposed to diminish probability of such failures. When used without arguments, the option instructs genrc to consult all variables from the list above, if their corresponding options are not given. You can also further restrict the use of environment to a subset of that list. For example, the above script can further be modified as

#! /bin/sh
PIDFILE=/var/run/ntpd.pid
export GENRC_COMMAND="/usr/sbin/ntpd -g -p $PIDFILE"
export GENRC_PID_FROM="FILE:$PIDFILE"
exec /sbin/genrc --env=GENRC_COMMAND,GENRC_PID_FROM \
     --no-reload --signal-stop=SIGHUP "$@"

This way, genrc will use only the two variables explicitly set in the script.

Up to version 1.5.3, environment variables were used by default. Obviously, existing scripts should be changed upon upgrading to version 2.0. To help catch the cases when people fail to do so, genrc issues a warning, if it detects that some of the above variables are set and the --env option is not supplied. For example (long lines being split for readability):

genrc: warning: the following environment variables are set,
       but not used:
genrc: GENRC_COMMAND
genrc: GENRC_SENTINEL
genrc: warning: use --env to use these variables, or --no-env to
       suppress this warning

The normal course of action when encountering such warning is to modify the script in question by either supplying the --env to genrc, so that it makes use of the environment, or by removing environment settings and using corresponding options instead.

The warning proposes also the third way: if, for some reason, you want to retain environment settings without actually using them, use the --no-env option to indicate that you are aware of the situation and its possible implications.


Prev: Next: Up: Top[Contents][Index]