| 1 |
<?xml version="1.0"?> |
| 2 |
<!--*-nxml-*--> |
| 3 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 4 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 5 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 6 |
<refentry id="systemd.preset"> |
| 7 |
|
| 8 |
<refentryinfo> |
| 9 |
<title>systemd.preset</title> |
| 10 |
<productname>systemd</productname> |
| 11 |
</refentryinfo> |
| 12 |
|
| 13 |
<refmeta> |
| 14 |
<refentrytitle>systemd.preset</refentrytitle> |
| 15 |
<manvolnum>5</manvolnum> |
| 16 |
</refmeta> |
| 17 |
|
| 18 |
<refnamediv> |
| 19 |
<refname>systemd.preset</refname> |
| 20 |
<refpurpose>Service enablement presets</refpurpose> |
| 21 |
</refnamediv> |
| 22 |
|
| 23 |
<refsynopsisdiv> |
| 24 |
<para><simplelist> |
| 25 |
<member><filename>/etc/systemd/system-preset/*.preset</filename></member> |
| 26 |
<member><filename>/run/systemd/system-preset/*.preset</filename></member> |
| 27 |
<member><filename>/usr/local/lib/systemd/system-preset/*.preset</filename></member> |
| 28 |
<member><filename>/usr/lib/systemd/system-preset/*.preset</filename></member> |
| 29 |
<member><filename>/etc/systemd/user-preset/*.preset</filename></member> |
| 30 |
<member><filename>/run/systemd/user-preset/*.preset</filename></member> |
| 31 |
<member><filename>/usr/local/lib/systemd/user-preset/*.preset</filename></member> |
| 32 |
<member><filename>/usr/lib/systemd/user-preset/*.preset</filename></member> |
| 33 |
<member><filename>/etc/systemd/initrd-preset/*.preset</filename></member> |
| 34 |
<member><filename>/run/systemd/initrd-preset/*.preset</filename></member> |
| 35 |
<member><filename>/usr/local/lib/systemd/initrd-preset/*.preset</filename></member> |
| 36 |
<member><filename>/usr/lib/systemd/initrd-preset/*.preset</filename></member> |
| 37 |
</simplelist></para> |
| 38 |
</refsynopsisdiv> |
| 39 |
|
| 40 |
<refsect1> |
| 41 |
<title>Description</title> |
| 42 |
|
| 43 |
<para>Preset files may be used to encode policy which units shall be enabled by default and which ones |
| 44 |
shall be disabled. They are read by <command>systemctl preset</command> which uses this information to |
| 45 |
enable or disable a unit. Depending on that policy, <command>systemctl preset</command> is identical to |
| 46 |
<command>systemctl enable</command> or <command>systemctl disable</command>. |
| 47 |
|
| 48 |
<command>systemctl preset</command> is used by the post install scriptlets of rpm packages (or other OS |
| 49 |
package formats), to enable/disable specific units by default on package installation, enforcing |
| 50 |
distribution, spin, or administrator preset policy. This allows choosing a certain set of units to be |
| 51 |
enabled/disabled even before installing the actual package. For more information, see |
| 52 |
<citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para> |
| 53 |
|
| 54 |
<para>It is not recommended to ship preset files within the respective software packages implementing the |
| 55 |
units, but rather centralize them in a distribution or spin default policy, which can be amended by |
| 56 |
administrator policy, see below.</para> |
| 57 |
|
| 58 |
<para>If no preset files exist, preset operations will enable all units that are installed by default. If |
| 59 |
this is not desired and all units shall rather be disabled, it is necessary to ship a preset file with a |
| 60 |
single, catchall "<filename>disable *</filename>" line. (See example 1, below.)</para> |
| 61 |
|
| 62 |
<para>When the machine is booted for the first time, |
| 63 |
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> will |
| 64 |
enable/disable all units according to preset policy, similarly to <command>systemctl |
| 65 |
preset-all</command>. Also see <varname>ConditionFirstBoot=</varname> in |
| 66 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> and |
| 67 |
"First Boot Semantics" in |
| 68 |
<citerefentry><refentrytitle>machine-id</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 69 |
</para> |
| 70 |
</refsect1> |
| 71 |
|
| 72 |
<refsect1> |
| 73 |
<title>Preset File Format</title> |
| 74 |
|
| 75 |
<para>The preset files contain a list of directives, one per line. Empty lines and lines whose first |
| 76 |
non-whitespace character is <literal>#</literal> or <literal>;</literal> are ignored. Each directive |
| 77 |
consists of one of the words <literal>enable</literal>, <literal>disable</literal>, or |
| 78 |
<literal>ignore</literal>, followed by whitespace and a unit name. The unit name may contain shell-style |
| 79 |
wildcards.</para> |
| 80 |
|
| 81 |
<para>For the enable directive for template units, one or more instance names may be specified as a |
| 82 |
space-separated list after the unit name. In this case, those instances will be enabled instead of the |
| 83 |
instance specified via DefaultInstance= in the unit.</para> |
| 84 |
|
| 85 |
<para>Presets must refer to the "real" unit file, and not to any aliases. See |
| 86 |
<citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 87 |
for a description of unit aliasing.</para> |
| 88 |
|
| 89 |
<para>Three different directives are understood: <literal>enable</literal> may be used to enable units by |
| 90 |
default, <literal>disable</literal> to disable units by default, and <literal>ignore</literal> to ignore |
| 91 |
units and leave existing configuration intact.</para> |
| 92 |
|
| 93 |
<para>If multiple lines apply to a unit name, the first matching |
| 94 |
one takes precedence over all others.</para> |
| 95 |
|
| 96 |
<para>Each preset file shall be named in the style of |
| 97 |
<filename><priority>-<policy-name>.preset</filename>. Files |
| 98 |
in <filename>/etc/</filename> override files with the same name in |
| 99 |
<filename>/usr/lib/</filename> and <filename>/run/</filename>. |
| 100 |
Files in <filename>/run/</filename> override files with the same |
| 101 |
name in <filename>/usr/lib/</filename>. Packages should install |
| 102 |
their preset files in <filename>/usr/lib/</filename>. Files in |
| 103 |
<filename>/etc/</filename> are reserved for the local |
| 104 |
administrator, who may use this logic to override the preset files |
| 105 |
installed by vendor packages. All preset files are sorted by their |
| 106 |
filename in lexicographic order, regardless of which of the |
| 107 |
directories they reside in. If multiple files specify the same |
| 108 |
unit name, the entry in the file with the lexicographically |
| 109 |
earliest name will be applied. It is recommended to prefix all |
| 110 |
filenames with a two-digit number and a dash, to simplify the |
| 111 |
ordering of the files.</para> |
| 112 |
|
| 113 |
<para>If the administrator wants to disable a preset file supplied |
| 114 |
by the vendor, the recommended way is to place a symlink to |
| 115 |
<filename>/dev/null</filename> in |
| 116 |
<filename>/etc/systemd/system-preset/</filename> bearing the same |
| 117 |
filename.</para> |
| 118 |
</refsect1> |
| 119 |
|
| 120 |
<refsect1> |
| 121 |
<title>Examples</title> |
| 122 |
|
| 123 |
<example> |
| 124 |
<title>Default to off</title> |
| 125 |
|
| 126 |
<programlisting># /usr/lib/systemd/system-preset/99-default.preset |
| 127 |
|
| 128 |
disable *</programlisting> |
| 129 |
</example> |
| 130 |
|
| 131 |
<para>This disables all units. Due to the filename prefix |
| 132 |
<literal>99-</literal>, it will be read last and hence can easily |
| 133 |
be overridden by spin or administrator preset policy.</para> |
| 134 |
|
| 135 |
<example> |
| 136 |
<title>Enable multiple template instances</title> |
| 137 |
|
| 138 |
<programlisting># /usr/lib/systemd/system-preset/80-dirsrv.preset |
| 139 |
|
| 140 |
enable [email protected] foo bar baz</programlisting> |
| 141 |
</example> |
| 142 |
|
| 143 |
<para>This enables all three of <filename>[email protected]</filename>, |
| 144 |
<filename>[email protected]</filename> and <filename>[email protected]</filename>.</para> |
| 145 |
|
| 146 |
<example> |
| 147 |
<title>A GNOME spin</title> |
| 148 |
|
| 149 |
<programlisting># /usr/lib/systemd/system-preset/50-gnome.preset |
| 150 |
|
| 151 |
enable gdm.service |
| 152 |
enable colord.service |
| 153 |
enable accounts-daemon.service |
| 154 |
enable avahi-daemon.*</programlisting> |
| 155 |
|
| 156 |
</example> |
| 157 |
|
| 158 |
<para>This enables the three mentioned units, plus all |
| 159 |
<filename>avahi-daemon</filename> regardless of which unit type. A |
| 160 |
file like this could be useful for inclusion in a GNOME spin of a |
| 161 |
distribution. It will ensure that the units necessary for GNOME |
| 162 |
are properly enabled as they are installed. It leaves all other |
| 163 |
units untouched, and subject to other (later) preset files, for |
| 164 |
example like the one from the first example above.</para> |
| 165 |
|
| 166 |
<example> |
| 167 |
<title>Administrator policy</title> |
| 168 |
|
| 169 |
<programlisting># /etc/systemd/system-preset/00-lennart.preset |
| 170 |
|
| 171 |
enable httpd.service |
| 172 |
enable sshd.service |
| 173 |
enable postfix.service |
| 174 |
disable *</programlisting> |
| 175 |
</example> |
| 176 |
|
| 177 |
<para>This enables three specific services and disables all |
| 178 |
others. This is useful for administrators to specifically select |
| 179 |
the units to enable, and disable all others. Due to the filename |
| 180 |
prefix <literal>00-</literal> it will be read early and |
| 181 |
override all other preset policy files.</para> |
| 182 |
</refsect1> |
| 183 |
|
| 184 |
<refsect1> |
| 185 |
<title>Motivation for the preset logic</title> |
| 186 |
|
| 187 |
<para>Different distributions have different policies on which services shall be enabled by default when |
| 188 |
the package they are shipped in is installed. On Fedora all services stay off by default, so that |
| 189 |
installing a package will not cause a service to be enabled (with some exceptions). On Debian all |
| 190 |
services are immediately enabled by default, so that installing a package will cause its services to be |
| 191 |
enabled right-away.</para> |
| 192 |
|
| 193 |
<para>Even within a single distribution, different spins (flavours, remixes, whatever you might want to |
| 194 |
call them) of a distribution also have different policies on what services to enable, and what services |
| 195 |
to leave off. For example, Fedora Workstation will enable <command>gdm</command> as display manager by |
| 196 |
default, while the Fedora KDE spin will enable <command>sddm</command> instead.</para> |
| 197 |
|
| 198 |
<para>Different sites might also have different policies what to turn on by default and what to turn |
| 199 |
off. For example, one administrator would prefer to enforce the policy of "<command>sshd</command> should |
| 200 |
be always on, but everything else off", while another one might say "<command>snmpd</command> always on, |
| 201 |
and for everything else use the distribution policy defaults".</para> |
| 202 |
|
| 203 |
<para>Traditionally, policy about which services shall be enabled were implemented in each package |
| 204 |
individually. This made it cumbersome to implement different policies per spin or per site, or to create |
| 205 |
software packages that do the right thing on more than one distribution. The enablement mechanism was |
| 206 |
also encoding the enablement policy.</para> |
| 207 |
|
| 208 |
<para>The preset mechanism allows clean separation of the enablement mechanism (inside the package |
| 209 |
scriptlets, by invoking <command>systemctl preset</command>) and enablement policy (centralized in the |
| 210 |
preset files), and lifts the configuration out of individual packages. Preset files may be written for |
| 211 |
specific distributions, for specific spins or for specific sites, in order to enforce different policies |
| 212 |
as needed. It is recommended to apply the policy encoded in preset files in package installation |
| 213 |
scriptlets.</para> |
| 214 |
</refsect1> |
| 215 |
|
| 216 |
<refsect1> |
| 217 |
<title>See Also</title> |
| 218 |
<para><simplelist type="inline"> |
| 219 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 220 |
<member><citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 221 |
<member><citerefentry><refentrytitle>systemd-delta</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 222 |
</simplelist></para> |
| 223 |
|
| 224 |
<para><citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry> |
| 225 |
has a discussion of packaging scriptlets.</para> |
| 226 |
|
| 227 |
<para>Fedora page introducing the use of presets: |
| 228 |
<ulink url="https://fedoraproject.org/wiki/Features/PackagePresets">Features/PackagePresets</ulink>. |
| 229 |
</para> |
| 230 |
</refsect1> |
| 231 |
|
| 232 |
</refentry> |