From Fedora Project Wiki
(Created page with "=== EnvironmentFiles and support for /etc/sysconfig files === The <code>EnvironmentFiles=</code> line in the <code>[Service]</code> section of <code>.service</code> files is use...")
 
(Change one sysconfig files reference to be more specific)
Line 12: Line 12:
</pre>
</pre>


You may then refer to variables set in sysconfig files with
You may then refer to variables set in the /etc/sysconfig/httpd file with
<code>${FOOBAR}</code> and <code>$FOOBAR</code>, in the <code>ExecStart=</code>
<code>${FOOBAR}</code> and <code>$FOOBAR</code>, in the <code>ExecStart=</code>
lines (and related lines). (<code>${FOOBAR}</code> expands the variable into
lines (and related lines). (<code>${FOOBAR}</code> expands the variable into

Revision as of 17:49, 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 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.