(Mark as <code>) |
(relax =- recommendation) |
||
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 | 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. 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 18:05, 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. 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.