From Fedora Project Wiki
(relax =- recommendation)
 
Line 20: Line 20:
The "-" on the <code>EnvironmentFile=</code> 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 include the "-" when using this directive.
The "-" on the <code>EnvironmentFile=</code> 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 include the "-" when using this directive.


Although environment files are easy to use, upstream systemd recommends a different approach.  The recommended way for administrators to reconfigure systemd <code>.service</code> files is to copy them from <code>/lib/systemd/system</code> to <code>/etc/systemd/system</code> and modify them there. Unit files in <code>/etc/systemd/system</code> override those in <code>/lib/systemd/system</code> if they otherwise carry the same name. Both approaches are valid in Fedora.
Although environment files are easy to use, upstream systemd recommends a different approach.  Their recommendation for administrators who need to reconfigure systemd <code>.service</code> files is to copy them from <code>/lib/systemd/system</code> to <code>/etc/systemd/system</code> and modify them there. Unit files in <code>/etc/systemd/system</code> override those in <code>/lib/systemd/system</code> if they otherwise carry the same name.
 
Either approach is valid in Fedora.

Latest revision as of 18:07, 21 March 2012

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 include the "-" when using this directive.

Although environment files are easy to use, upstream systemd recommends a different approach. Their recommendation for administrators who need 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.

Either approach is valid in Fedora.