From Fedora Project Wiki
(Change one sysconfig files reference to be more specific)
(Mark as <code>)
Line 12: Line 12:
</pre>
</pre>


You may then refer to variables set in the /etc/sysconfig/httpd file with
You may then refer to variables set in the <code>/etc/sysconfig/httpd</code> 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
Line 18: Line 18:
multiple words)
multiple words)


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 always include the "-" when usingthis 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 always 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.  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.

Revision as of 17:50, 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 using this 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.