HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

man/systemd.service.xml

123,825 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 3877cd6101a1cb76cd56ea29a9f82e2da67777a8

Lines 1001–2000 of 2,015

                <entry/>
                <entry>X</entry>
                <entry/>
                <entry>X</entry>
                <entry>X</entry>
                <entry/>
                <entry/>
              </row>
              <row>
                <entry>Watchdog</entry>
                <entry/>
                <entry>X</entry>
                <entry/>
                <entry>X</entry>
                <entry>X</entry>
                <entry/>
                <entry>X</entry>
              </row>
              <row>
                <entry>Termination due to OOM</entry>
                <entry/>
                <entry>X</entry>
                <entry/>
                <entry>X</entry>
                <entry>X</entry>
                <entry/>
                <entry/>
              </row>
            </tbody>
          </tgroup>
        </table>
 
        <para>As exceptions to the setting above, the service will not
        be restarted if the exit code or signal is specified in
        <varname>RestartPreventExitStatus=</varname> (see below) or
        the service is stopped with <command>systemctl stop</command>
        or an equivalent operation. Also, the services will always be
        restarted if the exit code or signal is specified in
        <varname>RestartForceExitStatus=</varname> (see below).</para>
 
        <para>Note that service restart is subject to unit start rate
        limiting configured with <varname>StartLimitIntervalSec=</varname>
        and <varname>StartLimitBurst=</varname>, see
        <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
        for details.</para>
 
        <para>Setting this to <option>on-failure</option> is the
        recommended choice for long-running services, in order to
        increase reliability by attempting automatic recovery from
        errors. For services that shall be able to terminate on their
        own choice (and avoid immediate restarting),
        <option>on-abnormal</option> is an alternative choice.</para>
        </listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>RestartMode=</varname></term>
 
        <listitem>
          <para>Takes a string value that specifies how a service should restart:
            <itemizedlist>
              <listitem>
                <para>If set to <option>normal</option> (the default), the service restarts by going through
                a failed/inactive state.</para>
 
                <xi:include href="version-info.xml" xpointer="v254"/>
              </listitem>
 
              <listitem>
                <para>If set to <option>direct</option>, the service transitions to the activating
                state directly during auto-restart, skipping failed/inactive state.
                <varname>ExecStopPost=</varname> is still invoked.
                <varname>OnSuccess=</varname> and <varname>OnFailure=</varname> are skipped.</para>
 
                <para>This option is useful in cases where a dependency can fail temporarily but we do not
                want these temporary failures to make the dependent units fail. Dependent units are not
                notified of these temporary failures.</para>
 
                <xi:include href="version-info.xml" xpointer="v254"/>
              </listitem>
 
              <listitem>
                <para>If set to <option>debug</option>, the service manager will log messages that are
                related to this unit at debug level while automated restarts are attempted, until either the
                service hits the rate limit or it succeeds, and the <varname>$DEBUG_INVOCATION=1</varname>
                environment variable will be set for the unit. This is useful to be able to get additional
                information when a service fails to start, without needing to proactively or permanently
                enable debug level logging in systemd, which is very verbose. This is otherwise equivalent
                to <option>normal</option> mode.</para>
 
                <xi:include href="version-info.xml" xpointer="v257"/>
              </listitem>
            </itemizedlist>
          </para>
 
          <xi:include href="version-info.xml" xpointer="v254"/>
        </listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>SuccessExitStatus=</varname></term>
 
        <listitem><para>Takes a list of exit status definitions that, when returned by the main service
        process, will be considered successful termination, in addition to the normal successful exit status
        0 and, except for <varname>Type=oneshot</varname>, the signals <constant>SIGHUP</constant>, <constant>SIGINT</constant>,
        <constant>SIGTERM</constant>, and <constant>SIGPIPE</constant>. Exit status definitions can be
        numeric termination statuses, termination status names, or termination signal names, separated by
        spaces. See the Process Exit Codes section in
        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
        a list of termination status names (for this setting only the part without the
        <literal>EXIT_</literal> or <literal>EX_</literal> prefix should be used). See <citerefentry
        project='man-pages'><refentrytitle>signal</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
        a list of signal names.</para>
 
        <para>Note that this setting does not change the mapping between numeric exit statuses and their
        names, i.e. regardless how this setting is used 0 will still be mapped to <literal>SUCCESS</literal>
        (and thus typically shown as <literal>0/SUCCESS</literal> in tool outputs) and 1 to
        <literal>FAILURE</literal> (and thus typically shown as <literal>1/FAILURE</literal>), and so on. It
        only controls what happens as effect of these exit statuses, and how it propagates to the state of
        the service as a whole.</para>
 
        <para>This option may appear more than once, in which case the list of successful exit statuses is
        merged. If the empty string is assigned to this option, the list is reset, all prior assignments of
        this option will have no effect.</para>
 
        <example>
          <title>A service with the <varname>SuccessExitStatus=</varname> setting</title>
 
          <programlisting>SuccessExitStatus=TEMPFAIL 250 SIGKILL</programlisting>
 
          <para>Exit status 75 (<constant>TEMPFAIL</constant>), 250, and the termination signal
          <constant>SIGKILL</constant> are considered clean service terminations.</para>
        </example>
 
        <para>Note: <command>systemd-analyze exit-status</command> may be used to list exit statuses and
        translate between numerical status values and names.</para>
 
        <xi:include href="version-info.xml" xpointer="v189"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>RestartPreventExitStatus=</varname></term>
 
        <listitem><para>Takes a list of exit status definitions that, when returned by the main service
        process, will prevent automatic service restarts, regardless of the restart setting configured with
        <varname>Restart=</varname>. Exit status definitions can be numeric termination statuses, termination
        status names, or termination signal names, separated by spaces. Defaults to the empty list, so that,
        by default, no exit status is excluded from the configured restart logic.
 
        <example>
          <title>A service with the <varname>RestartPreventExitStatus=</varname> setting</title>
 
          <programlisting>RestartPreventExitStatus=TEMPFAIL 250 SIGKILL</programlisting>
 
          <para>Exit status 75 (<constant>TEMPFAIL</constant>), 250, and the termination signal
          <constant>SIGKILL</constant> will not result in automatic service restarting.</para>
        </example>
 
        This option may appear more than once, in which case the list of restart-preventing statuses is merged.
        If the empty string is assigned to this option, the list is reset and all prior assignments of this
        option will have no effect.</para>
 
        <para>Note that this setting has no effect on processes configured via
        <varname>ExecStartPre=</varname>, <varname>ExecStartPost=</varname>, <varname>ExecStop=</varname>,
        <varname>ExecStopPost=</varname> or <varname>ExecReload=</varname>, but only on the main service
        process, i.e. either the one invoked by <varname>ExecStart=</varname> or (depending on
        <varname>Type=</varname>, <varname>PIDFile=</varname>, …) the otherwise configured main
        process.</para>
 
        <xi:include href="version-info.xml" xpointer="v189"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>RestartForceExitStatus=</varname></term>
 
        <listitem><para>Takes a list of exit status definitions that, when returned by the main service
        process, will force automatic service restarts, regardless of the restart setting configured with
        <varname>Restart=</varname>. The argument format is similar to <varname>RestartPreventExitStatus=</varname>.
        </para>
 
        <para>Note that for <varname>Type=oneshot</varname> services, a success exit status will prevent
        them from auto-restarting, no matter whether the corresponding exit statuses are listed in this
        option or not.</para>
 
        <xi:include href="version-info.xml" xpointer="v215"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>RootDirectoryStartOnly=</varname></term>
        <listitem><para>Takes a boolean argument. If true, the root directory, as configured with the
        <varname>RootDirectory=</varname> option (see
        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
        for more information), is only applied to the process started with <varname>ExecStart=</varname>,
        and not to the various other <varname>ExecStartPre=</varname>, <varname>ExecStartPost=</varname>,
        <varname>ExecReload=</varname>, <varname>ExecReloadPost=</varname>, <varname>ExecStop=</varname>,
        and <varname>ExecStopPost=</varname> commands. If false, the setting is applied to all
        configured commands the same way. Defaults to false.</para></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>NonBlocking=</varname></term>
        <listitem><para>Set the <constant>O_NONBLOCK</constant> flag for all file descriptors passed via
        socket-based activation. If true, all file descriptors >= 3 (i.e. all except stdin, stdout, stderr),
        excluding those passed in via the file descriptor storage logic (see
        <varname>FileDescriptorStoreMax=</varname> for details), will have the
        <constant>O_NONBLOCK</constant> flag set and hence are in non-blocking mode. This option is only
        useful in conjunction with a socket unit, as described in
        <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>
        and has no effect on file descriptors which were previously saved in the file-descriptor store for
        example.  Defaults to false.</para>
 
        <para>Note that if the same socket unit is configured to be passed to multiple service units (via the
        <varname>Sockets=</varname> setting, see below), and these services have different
        <varname>NonBlocking=</varname> configurations, the precise state of <constant>O_NONBLOCK</constant>
        depends on the order in which these services are invoked, and will possibly change after service code
        already took possession of the socket file descriptor, simply because the
        <constant>O_NONBLOCK</constant> state of a socket is shared by all file descriptors referencing
        it. Hence it is essential that all services sharing the same socket use the same
        <varname>NonBlocking=</varname> configuration, and do not change the flag in service code
        either.</para></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>NotifyAccess=</varname></term>
        <listitem><para>Controls access to the service status notification socket, as accessible via the
        <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
        call. Takes one of <option>none</option> (the default), <option>main</option>, <option>exec</option>
        or <option>all</option>. If <option>none</option>, no daemon status updates are accepted from the
        service processes, all status update messages are ignored. If <option>main</option>, only service
        updates sent from the main process of the service are accepted. If <option>exec</option>, only
        service updates sent from any of the main or control processes originating from one of the
        <varname>Exec*=</varname> commands are accepted. If <option>all</option>, all services updates from
        all members of the service's control group are accepted. This option should be set to open access to
        the notification socket when using
        <varname>Type=notify</varname>/<varname>Type=notify-reload</varname> or
        <varname>WatchdogSec=</varname> (see above). If those options are used but
        <varname>NotifyAccess=</varname> is not configured, it will be implicitly set to
        <option>main</option>.</para>
 
        <para>Note that <function>sd_notify()</function> notifications may be attributed to units correctly only if
        either the sending process is still around at the time PID 1 processes the message, or if the sending process
        is explicitly runtime-tracked by the service manager. The latter is the case if the service manager originally
        forked off the process, i.e. on all processes that match <option>main</option> or
        <option>exec</option>. Conversely, if an auxiliary process of the unit sends an
        <function>sd_notify()</function> message and immediately exits, the service manager might not be able to
        properly attribute the message to the unit, and thus will ignore it, even if
        <varname>NotifyAccess=</varname><option>all</option> is set for it.</para>
 
        <para>Hence, to eliminate all race conditions involving lookup of the client's unit and attribution of notifications
        to units correctly, <function>sd_notify_barrier()</function> may be used. This call acts as a synchronization point
        and ensures all notifications sent before this call have been picked up by the service manager when it returns
        successfully. Use of <function>sd_notify_barrier()</function> is needed for clients which are not invoked by the
        service manager, otherwise this synchronization mechanism is unnecessary for attribution of notifications to the
        unit.</para></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>Sockets=</varname></term>
        <listitem><para>Specifies the name of the socket units this
        service shall inherit socket file descriptors from when the
        service is started. Normally, it should not be necessary to use
        this setting, as all socket file descriptors whose unit shares
        the same name as the service (subject to the different unit
        name suffix of course) are passed to the spawned
        process.</para>
 
        <para>Note that the same socket file descriptors may be passed
        to multiple processes simultaneously. Also note that a
        different service may be activated on incoming socket traffic
        than the one which is ultimately configured to inherit the
        socket file descriptors. Or, in other words: the
        <varname>Service=</varname> setting of
        <filename>.socket</filename> units does not have to match the
        inverse of the <varname>Sockets=</varname> setting of the
        <filename>.service</filename> it refers to.</para>
 
        <para>This option may appear more than once, in which case the list of socket units is merged. Note
        that once set, clearing the list of sockets again (for example, by assigning the empty string to this
        option) is not supported.</para></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>FileDescriptorStoreMax=</varname></term>
        <listitem><para>Configure how many file descriptors may be stored in the service manager for the
        service using
        <citerefentry><refentrytitle>sd_pid_notify_with_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>'s
        <literal>FDSTORE=1</literal> messages. This is useful for implementing services that can restart
        after an explicit request or a crash without losing state. Any open sockets and other file
        descriptors which should not be closed during the restart may be stored this way. Application state
        can either be serialized to a file in <varname>RuntimeDirectory=</varname>, or stored in a
        <citerefentry><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>
        memory file descriptor. Defaults to 0, i.e. no file descriptors may be stored in the service
        manager. All file descriptors passed to the service manager from a specific service are passed back
        to the service's main process on the next service restart (see
        <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry> for
        details about the precise protocol used and the order in which the file descriptors are passed). Any
        file descriptors passed to the service manager are automatically closed when
        <constant>POLLHUP</constant> or <constant>POLLERR</constant> is seen on them, or when the service is
        fully stopped and no job is queued or being executed for it (the latter can be tweaked with
        <varname>FileDescriptorStorePreserve=</varname>, see below). If this option is used,
        <varname>NotifyAccess=</varname> (see above) should be set to open access to the notification socket
        provided by systemd. If <varname>NotifyAccess=</varname> is not set, it will be implicitly set to
        <option>main</option>.</para>
 
        <para>The <command>fdstore</command> command of
        <citerefentry><refentrytitle>systemd-analyze</refentrytitle><manvolnum>1</manvolnum></citerefentry>
        may be used to list the current contents of a service's file descriptor store.</para>
 
        <para>Note that the service manager will only pass file descriptors contained in the file descriptor
        store to the service's own processes, never to other clients via IPC or similar. However, it does
        allow unprivileged clients to query the list of currently open file descriptors of a
        service. Sensitive data may hence be safely placed inside the referenced files, but should not be
        attached to the metadata (e.g. included in filenames) of the stored file
        descriptors.</para>
 
        <para>If this option is set to a non-zero value the <varname>$FDSTORE</varname> environment variable
        will be set for processes invoked for this service. See
        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
        details.</para>
 
        <para>For further information on the file descriptor store see the <ulink
        url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> overview.</para>
 
        <xi:include href="version-info.xml" xpointer="v219"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>FileDescriptorStorePreserve=</varname></term>
        <listitem><para>Takes one of <constant>no</constant>, <constant>yes</constant>,
        <constant>restart</constant>, <constant>on-success</constant> and controls when to release the
        service's file descriptor store (i.e. when to close the contained file descriptors, if any). If set
        to <constant>no</constant> the file descriptor store is automatically released when the service is
        stopped; if <constant>restart</constant> (the default) it is kept around as long as the unit is
        neither inactive nor failed, or a job is queued for the service, or the service is expected to be
        restarted. If <constant>yes</constant> the file descriptor store is kept around and garbage
        collection of the unit is disabled. The latter is useful to keep entries in the file descriptor
        store pinned until the unit is removed, the service manager exits, or the file descriptors get
        <constant>EPOLLHUP</constant> or <constant>EPOLLERR</constant>. If <constant>on-success</constant>
        the behaviour is identical to <constant>yes</constant>, except that the file descriptor store is
        discarded if the unit enters the permanent <literal>failed</literal> state (i.e. once all automated
        restart attempts driven by <varname>Restart=</varname> have been exhausted). The store is preserved
        across the transitionary failed states that precede each individual auto-restart attempt.</para>
 
        <para>When set to <constant>yes</constant> or <constant>on-success</constant>, and the service is
        itself running under another service manager (e.g. a service of <filename>user@.service</filename>,
        or a payload inside
        <citerefentry><refentrytitle>systemd-nspawn</refentrytitle><manvolnum>1</manvolnum></citerefentry>),
        file descriptors pushed into the store are also forwarded one level up via the enveloping manager's
        <varname>$NOTIFY_SOCKET</varname>, tagged with the originating unit id, so that they are preserved
        across restarts of the inner manager and handed back to the originating unit when it is started
        again. For this to take effect, the enveloping unit must itself enable
        <varname>FileDescriptorStoreMax=</varname> and a non-<constant>no</constant>/<constant>restart</constant>
        value for <varname>FileDescriptorStorePreserve=</varname>.
        See the <ulink url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink>
        overview for details.</para>
 
        <para>Setting this to <constant>yes</constant> or <constant>on-success</constant> also ensures the
        file descriptor store is kept loaded across a <literal>kexec</literal>-based reboot on kernels
        supporting the <ulink
        url="https://docs.kernel.org/userspace-api/liveupdate.html">Live Update Orchestrator</ulink>,
        so that compatible file descriptors (such as <citerefentry
        project='man-pages'><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>)
        are preserved and handed back to the service on the other side. See the <ulink
        url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> overview for
        details.</para>
 
        <para>Use <command>systemctl clean --what=fdstore …</command> to release the file descriptor store
        explicitly.</para>
 
        <xi:include href="version-info.xml" xpointer="v254"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>LUOSession=</varname></term>
        <listitem><para>Takes a whitespace-separated list of names. For each name, when the service is
        started the service manager creates a LUO session via the <ulink
        url="https://docs.kernel.org/userspace-api/liveupdate.html">Live Update Orchestrator</ulink> (LUO,
        i.e. <filename>/dev/liveupdate</filename>) and hands the resulting session file descriptor to the
        service through the file descriptor store, using the configured name as its
        <literal>FDNAME=</literal>. The session is hence passed to the service's processes via
        <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
        like any other file descriptor store entry. The service may then preserve additional file
        descriptors (such as <citerefentry
        project='man-pages'><refentrytitle>memfd_create</refentrytitle><manvolnum>2</manvolnum></citerefentry>
        memory file descriptors) in the session, which survive a <literal>kexec</literal>-based reboot and
        can be retrieved again on the other side.</para>
 
        <para>A session is only handed out if one with the same name is not already present in the service's
        file descriptor store. This way a session handed out on first start, or restored across a
        <literal>kexec</literal>, is reused on the next start rather than replaced. The kernel-level session
        name is derived deterministically from the unit name and the configured name, so that it remains
        stable and unique, and it fits within the length limit imposed by the kernel.</para>
 
        <para>This setting implies <varname>FileDescriptorStoreMax=</varname> is set to at least the number
        of configured sessions. To ensure the sessions are kept pinned and preserved across a
        <literal>kexec</literal>, combine this with <varname>FileDescriptorStorePreserve=yes</varname> (see
        above). If <filename>/dev/liveupdate</filename> is not available no session is handed out, and the
        service is started normally. This setting may be specified more than once, in which case the lists
        are combined. If the empty string is assigned the list is reset and all prior assignments have no
        effect.</para>
 
        <para>For further information on the file descriptor store see the <ulink
        url="https://systemd.io/FILE_DESCRIPTOR_STORE">File Descriptor Store</ulink> overview.</para>
 
        <xi:include href="system-only.xml" xpointer="singular"/>
        <xi:include href="version-info.xml" xpointer="v262"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>USBFunctionDescriptors=</varname></term>
        <listitem><para>Configure the location of a file containing
        <ulink
        url="https://docs.kernel.org/usb/functionfs.html">USB
        FunctionFS</ulink> descriptors, for implementation of USB
        gadget functions. This is used only in conjunction with a
        socket unit with <varname>ListenUSBFunction=</varname>
        configured. The contents of this file are written to the
        <filename>ep0</filename> file after it is
        opened.</para>
 
        <xi:include href="version-info.xml" xpointer="v227"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>USBFunctionStrings=</varname></term>
        <listitem><para>Configure the location of a file containing
        USB FunctionFS strings.  Behavior is similar to
        <varname>USBFunctionDescriptors=</varname>
        above.</para>
 
        <xi:include href="version-info.xml" xpointer="v227"/></listitem>
      </varlistentry>
 
      <varlistentry id='oom-policy'>
        <term><varname>OOMPolicy=</varname></term>
 
        <listitem><para>Configure the out-of-memory (OOM) killing policy for the kernel and the userspace OOM
        killer
        <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
        On Linux, when memory becomes scarce to the point that the kernel has trouble allocating memory for
        itself, it might decide to kill a running process in order to free up memory and reduce memory
        pressure. Note that <filename>systemd-oomd.service</filename> is a more flexible solution that aims
        to prevent out-of-memory situations for the userspace too, not just the kernel, by attempting to
        terminate services earlier, before the kernel would have to act.</para>
 
        <para>This setting takes one of <constant>continue</constant>, <constant>stop</constant> or
        <constant>kill</constant>. If set to <constant>continue</constant> and a process in the unit is
        killed by the OOM killer, this is logged but the unit continues running. If set to
        <constant>stop</constant> the event is logged and the unit's processes are terminated cleanly by the
        service manager. If set to <constant>kill</constant> and one of the unit's processes is killed by the
        OOM killer the kernel is instructed to kill all remaining processes of the unit too, by setting the
        <filename>memory.oom.group</filename> attribute to <constant>1</constant>; also see kernel page
        <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Group v2</ulink>. In case of
        both <constant>stop</constant> and <constant>kill</constant>, the service ultimately ends up in the
        <constant>oom-kill</constant> failed state after which <varname>Restart=</varname> may apply.
        </para>
 
        <para>Defaults to the setting <varname>DefaultOOMPolicy=</varname> in
        <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
        is set to, except for units where <varname>Delegate=</varname> is turned on, where it defaults to
        <constant>continue</constant>.</para>
 
        <para>Use the <varname>OOMScoreAdjust=</varname> setting to configure whether processes of the unit
        shall be considered preferred or less preferred candidates for process termination by the Linux OOM
        killer logic. See
        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
        details.</para>
 
        <para>This setting also applies to
        <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
        Similarly to the kernel OOM kills performed by the kernel, this setting determines the state of the
        unit after <command>systemd-oomd</command> kills a cgroup associated with it.</para>
 
        <xi:include href="version-info.xml" xpointer="v243"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>OpenFile=</varname></term>
        <listitem><para>Takes an argument of the form <literal>path<optional><replaceable>:fd-name:options</replaceable></optional></literal>,
        where:
        <itemizedlist>
            <listitem><simpara><literal>path</literal> is a path to a file or an <constant>AF_UNIX</constant> socket in the file system;</simpara></listitem>
            <listitem><simpara><literal>fd-name</literal> is a name that will be associated with the file descriptor;
            the name may contain any ASCII character, but must exclude control characters and ":", and must be at most 255 characters in length;
            it is optional and, if not provided, defaults to the file name;</simpara></listitem>
            <listitem><simpara><literal>options</literal> is a comma-separated list of access options;
            possible values are
            <literal>read-only</literal>,
            <literal>append</literal>,
            <literal>truncate</literal>,
            <literal>graceful</literal>;
            if not specified, files will be opened in <constant>rw</constant> mode;
            if <literal>graceful</literal> is specified, errors during file/socket opening are ignored.
            Specifying the same option several times is treated as an error.</simpara></listitem>
        </itemizedlist>
        The file or socket is opened by the service manager and the file descriptor is passed to the service.
        If the path is a socket, we call <function>connect()</function> on it.
        See <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>
        for more details on how to retrieve these file descriptors.</para>
 
        <para>This setting is useful to allow services to access files/sockets that they cannot access themselves
        (due to running in a separate mount namespace, not having privileges, ...).</para>
 
        <para>This setting can be specified multiple times, in which case all the specified paths are opened and the file descriptors passed to the service.
        If the empty string is assigned, the entire list of open files defined prior to this is reset.</para>
 
        <xi:include href="version-info.xml" xpointer="v253"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>ReloadSignal=</varname></term>
        <listitem><para>Configures the UNIX process signal to send to the service's main process when asked
        to reload the service's configuration. Defaults to <constant>SIGHUP</constant>. This option has no
        effect unless <varname>Type=</varname><option>notify-reload</option> is used, see
        above.</para>
 
        <xi:include href="version-info.xml" xpointer="v253"/></listitem>
      </varlistentry>
 
      <varlistentry>
        <term><varname>RefreshOnReload=</varname></term>
 
        <listitem><para>Takes a boolean argument, or a list of resources defined in
        <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
        Possible values are <option>extensions</option> and <option>credentials</option>, separated by space.
        Prepending the list with a single tilde character (<literal>~</literal>) inverts the effect.
        Defaults to <option>extensions</option>. An empty assignment resets the list to default. If enabled,
        the corresponding resources (<option>ExtensionImages=</option>/<option>ExtensionDirectories=</option>
        for <option>extensions</option> and <option>LoadCredential=</option>/<option>ImportCredential=</option>/
        <option>SetCredential=</option> (along with their <option>Encrypted</option> counterparts)
        for <option>credentials</option>) will be refreshed on service reload. If <option>yes</option>,
        all resources listed above that are used by the service shall be refreshed.</para>
 
        <para>Specially, if this option is set explicitly, and the respective resources are in use,
        the service may be reloaded without any actual reload mechanism (<option>ExecReload=</option>
        or <option>Type=notify-reload</option>) for notifying the main process, in which case the reload
        is considered complete immediately after refreshing.</para>
 
        <xi:include href="version-info.xml" xpointer="v260"/></listitem>
      </varlistentry>
 
    </variablelist>
 
    <para id='shared-unit-options'>Check
    <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
    <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>, and
    <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry> for more
    settings.</para>
  </refsect1>
 
  <refsect1>
    <title>Command lines</title>
 
    <para>This section describes command line parsing and
    variable and specifier substitutions for
    <varname>ExecStart=</varname>,
    <varname>ExecStartPre=</varname>,
    <varname>ExecStartPost=</varname>,
    <varname>ExecReload=</varname>,
    <varname>ExecStop=</varname>,
    <varname>ExecStopPost=</varname>, and
    <varname>ExecCondition=</varname> options.</para>
 
    <para>Multiple command lines may be specified by using the relevant setting multiple times.</para>
 
    <para>Each command line is unquoted using the rules described in "Quoting" section in
    <citerefentry><refentrytitle>systemd.syntax</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The
    first item becomes the command to execute, and the subsequent items the arguments.</para>
 
    <para>This syntax is inspired by shell syntax, but only the meta-characters and expansions
    described in the following paragraphs are understood, and the expansion of variables is
    different. Specifically, redirection using
    <literal>&lt;</literal>,
    <literal>&lt;&lt;</literal>,
    <literal>&gt;</literal>, and
    <literal>&gt;&gt;</literal>, pipes using
    <literal>|</literal>, running programs in the background using
    <literal>&amp;</literal>, and <emphasis>other elements of shell
    syntax are not supported</emphasis>.</para>
 
    <para>The command to execute may contain spaces, but control characters are not allowed.</para>
 
    <para>Each command may be prefixed with a number of special characters:</para>
 
    <table>
      <title>Special executable prefixes</title>
 
      <tgroup cols='2'>
        <colspec colname='prefix'/>
        <colspec colname='meaning'/>
 
        <thead>
          <row>
            <entry>Prefix</entry>
            <entry>Effect</entry>
          </row>
        </thead>
        <tbody>
          <row>
            <entry><literal>@</literal></entry>
            <entry>If the executable path is prefixed with <literal>@</literal>, the second specified token will be passed as <constant>argv[0]</constant> to the executed process (instead of the actual filename), followed by the further arguments specified, unless <literal>|</literal> is also specified, in which case it enables login shell semantics for the shell spawned by prefixing <literal>-</literal> to <constant>argv[0]</constant>.</entry>
          </row>
 
          <row>
            <entry><literal>-</literal></entry>
            <entry>If the executable path is prefixed with <literal>-</literal>, an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is recorded, but has no further effect and is considered equivalent to success.</entry>
          </row>
 
          <row>
            <entry><literal>:</literal></entry>
            <entry>If the executable path is prefixed with <literal>:</literal>, environment variable substitution (as described below this table) is not applied.</entry>
          </row>
 
          <row>
            <entry><literal>+</literal></entry>
            <entry>If the executable path is prefixed with <literal>+</literal> then the process is executed with full privileges. In this mode privilege restrictions configured with <varname>User=</varname>, <varname>Group=</varname>, <varname>CapabilityBoundingSet=</varname> or the various file system namespacing options (such as <varname>PrivateDevices=</varname>, <varname>PrivateTmp=</varname>) are not applied to the invoked command line (but still affect any other <varname>ExecStart=</varname>, <varname>ExecStop=</varname>, … lines). Resource limits configured with <varname>LimitCPU=</varname>, <varname>LimitCORE=</varname>, <varname>LimitNOFILE=</varname> and the other resource limit settings described in <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> (including the defaults set with <varname>DefaultLimitCPU=</varname>, <varname>DefaultLimitCORE=</varname>, … in <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>) are not applied either, and the invoked command inherits the resource limits of the service manager itself. However, note that this will not bypass options that apply to the whole control group, such as <varname>DevicePolicy=</varname>, see <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry> for the full list.</entry>
          </row>
 
          <row>
            <entry><literal>!</literal></entry>
 
            <entry>Similar to the <literal>+</literal> character discussed above this permits invoking command lines with elevated privileges. However, unlike <literal>+</literal> the <literal>!</literal> character exclusively alters the effect of <varname>User=</varname>, <varname>Group=</varname> and <varname>SupplementaryGroups=</varname>, i.e. only the stanzas that affect user and group credentials. Note that this setting may be combined with <varname>DynamicUser=</varname>, in which case a dynamic user/group pair is allocated before the command is invoked, but credential changing is left to the executed process itself.</entry>
          </row>
 
          <row>
            <entry><literal>|</literal></entry>
 
            <entry>If <literal>|</literal> is specified standalone as executable path, invoke the default shell of <varname>User=</varname>. If specified as a prefix, use the shell (<literal>-c</literal>) to spawn the executable. When <literal>@</literal> is used in conjunction, <constant>argv[0]</constant> of shell will be prefixed with <literal>-</literal> to enable login shell semantics.</entry>
          </row>
        </tbody>
      </tgroup>
    </table>
 
    <para><literal>@</literal>, <literal>|</literal>, <literal>-</literal>, <literal>:</literal>, and one of
    <literal>+</literal>/<literal>!</literal> may be used together and they can appear in any order.
    However, <literal>+</literal> and <literal>!</literal> may not be specified at the same time.</para>
 
    <para>For each command, the first argument must be either an absolute path to an executable or a simple
    file name without any slashes. If the command is not a full (absolute) path, it will be resolved to a
    full path using a fixed search path determined at compilation time. Searched directories include
    <filename>/usr/local/bin/</filename>, <filename>/usr/bin/</filename>, and their
    <filename>sbin/</filename> counterparts (only on systems using split <filename>bin/</filename> and
    <filename>sbin/</filename>). It is thus safe to use just the executable name in case of executables
    located in any of the "standard" directories, and an absolute path must be used in other cases.  Hint:
    this search path may be queried using <command>systemd-path search-binaries-default</command>.</para>
 
    <para>The command line accepts <literal>%</literal> specifiers as described in
    <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
 
    <para>An argument solely consisting of <literal>;</literal> must be escaped, i.e. specified as <literal>\;</literal>.</para>
 
    <para>Basic environment variable substitution is supported. Use
    <literal>${FOO}</literal> as part of a word, or as a word of its
    own, on the command line, in which case it will be erased and replaced
    by the exact value of the environment variable (if any) including all
    whitespace it contains, always resulting in exactly a single argument.
    Use <literal>$FOO</literal> as a separate word on the command line, in
    which case it will be replaced by the value of the environment
    variable split at whitespace, resulting in zero or more arguments.
    For this type of expansion, quotes are respected when splitting
    into words, and afterwards removed.</para>
 
    <para>Example:</para>
 
    <programlisting>Environment="ONE=one" 'TWO=two two'
ExecStart=echo $ONE $TWO ${TWO}</programlisting>
 
    <para>This will execute <command>/bin/echo</command> with four
    arguments: <literal>one</literal>, <literal>two</literal>,
    <literal>two</literal>, and <literal>two two</literal>.</para>
 
    <para>Example:</para>
    <programlisting>Environment=ONE='one' "TWO='two two' too" THREE=
ExecStart=/bin/echo ${ONE} ${TWO} ${THREE}
ExecStart=/bin/echo $ONE $TWO $THREE</programlisting>
    <para>This results in <filename>/bin/echo</filename> being
    called twice, the first time with arguments
    <literal>one</literal>,
    <literal>'two two' too</literal>, <literal></literal>,
    and the second time with arguments
    <literal>one</literal>, <literal>two two</literal>,
    <literal>too</literal>.
    </para>
 
    <para>Unless for commands with the special executable prefix <literal>:</literal>,
    to pass a literal dollar sign, use <literal>$$</literal>.
    Variables whose value is not known at expansion time are treated
    as empty strings. Note that the first argument (i.e. the program
    to execute) may not be a variable.</para>
 
    <para>Variables to be used in this fashion may be defined through
    <varname>Environment=</varname> and
    <varname>EnvironmentFile=</varname>. In addition, variables listed
    in the section "Environment variables in spawned processes" in
    <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
    which are considered "static configuration", may be used (this
    includes e.g. <varname>$USER</varname>, but not
    <varname>$TERM</varname>).</para>
 
    <para>Note that shell command lines are not directly supported, and <literal>|</literal> invokes the user's
    default shell which isn't deterministic. It's recommended to specify a shell implementation explicitly
    if portability is desired. Example:</para>
    <programlisting>ExecStart=sh -c 'dmesg | tac'</programlisting>
 
    <para>Example:</para>
 
    <programlisting>ExecStart=echo one
ExecStart=echo "two two"</programlisting>
 
    <para>This will execute <command>echo</command> two times,
    each time with one argument: <literal>one</literal> and
    <literal>two two</literal>, respectively. Because two commands are
    specified, <varname>Type=oneshot</varname> must be used.</para>
 
    <para>Example:</para>
 
    <programlisting>Type=oneshot
ExecStart=:echo $USER
ExecStart=-false
ExecStart=+:@true $TEST</programlisting>
 
    <para>This will execute <command>/usr/bin/echo</command> with the literal argument
    <literal>$USER</literal> (<literal>:</literal> suppresses variable expansion), and then
    <command>/usr/bin/false</command> (the return value will be ignored because <literal>-</literal>
    suppresses checking of the return value), and <command>/usr/bin/true</command> (with elevated privileges,
    with <literal>$TEST</literal> as <constant>argv[0]</constant>).</para>
 
    <para>Example:</para>
 
    <programlisting>ExecStart=echo / &gt;/dev/null &amp; \; \
ls</programlisting>
 
    <para>This will execute <command>echo</command>
    with five arguments: <literal>/</literal>,
    <literal>&gt;/dev/null</literal>,
    <literal>&amp;</literal>, <literal>;</literal>, and
    <literal>ls</literal>.</para>
  </refsect1>
 
  <refsect1>
    <title>Examples</title>
 
    <example>
      <title>Simple service</title>
 
      <para>The following unit file creates a service that will
      execute <filename index="false">/usr/sbin/foo-daemon</filename>. Since no
      <varname>Type=</varname> is specified, the default
      <varname>Type=</varname><option>simple</option> will be assumed.
      systemd will assume the unit to be started immediately after the
      program has begun executing.</para>
 
      <programlisting>[Unit]
Description=Foo
 
[Service]
ExecStart=/usr/sbin/foo-daemon
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>Note that systemd assumes here that the process started by
      systemd will continue running until the service terminates. If
      the program daemonizes itself (i.e. forks), please use
      <varname>Type=</varname><option>forking</option> instead.</para>
 
      <para>Since no <varname>ExecStop=</varname> was specified,
      systemd will send SIGTERM to all processes started from this
      service, and after a timeout also SIGKILL. This behavior can be
      modified, see
      <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
      for details.</para>
 
      <para>Note that this unit type does not include any type of notification when a service has completed
      initialization. For this, you should use other unit types, such as
      <varname>Type=</varname><option>notify</option>/<varname>Type=</varname><option>notify-reload</option>
      if the service understands systemd's notification protocol,
      <varname>Type=</varname><option>forking</option> if the service can background itself or
      <varname>Type=</varname><option>dbus</option> if the unit acquires a DBus name once initialization is
      complete. See below.</para>
    </example>
 
    <example>
      <title>Oneshot service</title>
 
      <para>Sometimes, units should just execute an action without
      keeping active processes, such as a filesystem check or a
      cleanup action on boot. For this,
      <varname>Type=</varname><option>oneshot</option> exists. Units
      of this type will wait until the process specified terminates
      and then fall back to being inactive. The following unit will
      perform a cleanup action:</para>
 
      <programlisting>[Unit]
Description=Cleanup old Foo data
 
[Service]
Type=oneshot
ExecStart=/usr/sbin/foo-cleanup
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>Note that systemd will consider the unit to be in the
      state "starting" until the program has terminated, so ordered
      dependencies will wait for the program to finish before starting
      themselves. The unit will revert to the "inactive" state after
      the execution is done, never reaching the "active" state. That
      means another request to start the unit will perform the action
      again.</para>
 
      <para><varname>Type=</varname><option>oneshot</option> are the
      only service units that may have more than one
      <varname>ExecStart=</varname> specified. For units with multiple
      commands (<varname index="false">Type=oneshot</varname>), all commands will be run again.</para>
      <para> For <varname index="false">Type=oneshot</varname>, <varname>Restart=</varname><option>always</option>
      and <varname>Restart=</varname><option>on-success</option> are <emphasis>not</emphasis> allowed.</para>
    </example>
 
    <example>
      <title>Stoppable oneshot service</title>
 
      <para>Similarly to the oneshot services, there are sometimes
      units that need to execute a program to set up something and
      then execute another to shut it down, but no process remains
      active while they are considered "started". Network
      configuration can sometimes fall into this category. Another use
      case is if a oneshot service shall not be executed each time
      when they are pulled in as a dependency, but only the first
      time.</para>
 
      <para>For this, systemd knows the setting
      <varname>RemainAfterExit=</varname><option>yes</option>, which
      causes systemd to consider the unit to be active if the start
      action exited successfully. This directive can be used with all
      types, but is most useful with
      <varname>Type=</varname><option>oneshot</option> and
      <varname>Type=</varname><option>simple</option>. With
      <varname>Type=</varname><option>oneshot</option>, systemd waits
      until the start action has completed before it considers the
      unit to be active, so dependencies start only after the start
      action has succeeded. With
      <varname>Type=</varname><option>simple</option>, dependencies
      will start immediately after the start action has been
      dispatched. The following unit provides an example for a simple
      static firewall.</para>
 
      <programlisting>[Unit]
Description=Simple firewall
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/simple-firewall-start
ExecStop=/usr/local/sbin/simple-firewall-stop
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>Since the unit is considered to be running after the start
      action has exited, invoking <command>systemctl start</command>
      on that unit again will cause no action to be taken.</para>
    </example>
 
    <example>
      <title>Traditional forking services</title>
 
      <para>Many traditional daemons/services background (i.e. fork,
      daemonize) themselves when starting. Set
      <varname>Type=</varname><option>forking</option> in the
      service's unit file to support this mode of operation. systemd
      will consider the service to be in the process of initialization
      while the original program is still running. Once it exits
      successfully and at least a process remains (and
      <varname>RemainAfterExit=</varname><option>no</option>), the
      service is considered started.</para>
 
      <para>Often, a traditional daemon only consists of one process.
      Therefore, if only one process is left after the original
      process terminates, systemd will consider that process the main
      process of the service. In that case, the
      <varname>$MAINPID</varname> variable will be available in
      <varname>ExecReload=</varname>, <varname>ExecStop=</varname>,
      etc.</para>
 
      <para>In case more than one process remains, systemd will be
      unable to determine the main process, so it will not assume
      there is one. In that case, <varname>$MAINPID</varname> will not
      expand to anything. However, if the process decides to write a
      traditional PID file, systemd will be able to read the main PID
      from there. Please set <varname>PIDFile=</varname> accordingly.
      Note that the daemon should write that file before finishing
      with its initialization. Otherwise, systemd might try to read the
      file before it exists.</para>
 
      <para>The following example shows a simple daemon that forks and
      just starts one process in the background:</para>
 
      <programlisting>[Unit]
Description=My Simple Daemon
 
[Service]
Type=forking
ExecStart=/usr/sbin/my-simple-daemon -d
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>Please see
      <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
      for details on how you can influence the way systemd terminates
      the service.</para>
    </example>
 
    <example>
      <title>DBus services</title>
 
      <para>For services that acquire a name on the DBus system bus,
      use <varname>Type=</varname><option>dbus</option> and set
      <varname>BusName=</varname> accordingly. The service should not
      fork (daemonize). systemd will consider the service to be
      initialized once the name has been acquired on the system bus.
      The following example shows a typical DBus service:</para>
 
      <programlisting>[Unit]
Description=Simple DBus Service
 
[Service]
Type=dbus
BusName=org.example.simple-dbus-service
ExecStart=/usr/sbin/simple-dbus-service
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>For <emphasis>bus-activatable</emphasis> services, do not
      include a [Install] section in the systemd
      service file, but use the <varname>SystemdService=</varname>
      option in the corresponding DBus service file, for example
      (<filename>/usr/share/dbus-1/system-services/org.example.simple-dbus-service.service</filename>):</para>
 
      <programlisting>[D-BUS Service]
Name=org.example.simple-dbus-service
Exec=/usr/sbin/simple-dbus-service
User=root
SystemdService=simple-dbus-service.service</programlisting>
 
      <para>Please see
      <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
      for details on how you can influence the way systemd terminates
      the service.</para>
    </example>
 
    <example>
      <title>Services that notify systemd about their initialization</title>
 
      <para><varname>Type=</varname><option>simple</option> services are really easy to write, but have the
      major disadvantage of systemd not being able to tell when initialization of the given service is
      complete. For this reason, systemd supports a simple notification protocol that allows daemons to make
      systemd aware that they are done initializing. Use <varname>Type=</varname><option>notify</option> or
      <varname>Type=</varname><option>notify-reload</option> for this. A typical service file for such a
      daemon would look like this:</para>
 
      <programlisting>[Unit]
Description=Simple Notifying Service
 
[Service]
Type=notify-reload
ExecStart=/usr/sbin/simple-notifying-service
 
[Install]
WantedBy=multi-user.target</programlisting>
 
      <para>Note that the daemon has to support systemd's notification
      protocol, else systemd will think the service has not started yet
      and kill it after a timeout. For an example of how to update
      daemons to support this protocol transparently, take a look at
      <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
      systemd will consider the unit to be in the 'starting' state
      until a readiness notification has arrived.</para>
 
      <para>Please see
      <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>
      for details on how you can influence the way systemd terminates
      the service.</para>
 
      <para>To avoid code duplication, it is preferable to use
      <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
      when possible, especially when other APIs provided by
      <citerefentry><refentrytitle>libsystemd</refentrytitle><manvolnum>3</manvolnum></citerefentry> are
      also used, but note that the notification protocol is very simple and guaranteed to be stable as per
      the <ulink url="https://systemd.io/PORTABILITY_AND_STABILITY/">Interface Portability and Stability
      Promise</ulink>, so it can be reimplemented by services with no external dependencies. For a
      self-contained example, see
      <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
    </example>
  </refsect1>
 
  <refsect1>
      <title>See Also</title>