EnvironmentFiles and support for /etc/sysconfig files
The EnvironmentFiles=
line in the [Service]
section of .service
files is used to support loading environment variables that can be used in unit files. For instance, if your sysv-initscript used a file in /etc/sysconfig to set command line options, you can use EnvironmentFiles=
like so:
Example:
[Service] Type=forking EnvironmentFile=-/etc/sysconfig/httpd ExecStart=/usr/sbin/httpd $OPTIONS ExecReload=/usr/sbin/httpd $OPTIONS -k restart
You may then refer to variables set in the /etc/sysconfig/httpd file with
${FOOBAR}
and $FOOBAR
, in the ExecStart=
lines (and related lines). (${FOOBAR}
expands the variable into
one word, $FOOBAR
splits up the variable value at whitespace into
multiple words)
The "-" on the EnvironmentFile=
line ensures that no error messages is generated if the environment file does not exist. Since many of these files were optional in sysvinit, you should always include the "-" when usingthis directive.
Although environment files are easy to use, upstream systemd recommends a different approach. The recommended way for administrators to reconfigure systemd .service
files is to copy them from /lib/systemd/system
to /etc/systemd/system
and modify them there. Unit files in /etc/systemd/system
override those in /lib/systemd/system
if they otherwise carry the same name. Both approaches are valid in Fedora.