1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="systemd-poweroff.service">
9 <title>systemd-poweroff.service</title>
10 <productname>systemd</productname>
14 <refentrytitle>systemd-poweroff.service</refentrytitle>
15 <manvolnum>8</manvolnum>
19 <refname>systemd-poweroff.service</refname>
20 <refname>systemd-halt.service</refname>
21 <refname>systemd-reboot.service</refname>
22 <refname>systemd-kexec.service</refname>
23 <refname>systemd-shutdown</refname>
24 <refpurpose>System shutdown logic</refpurpose>
28 <para><filename>systemd-poweroff.service</filename></para>
29 <para><filename>systemd-halt.service</filename></para>
30 <para><filename>systemd-reboot.service</filename></para>
31 <para><filename>systemd-kexec.service</filename></para>
32 <para><filename>/usr/lib/systemd/systemd-shutdown</filename></para>
33 <para><filename>/usr/lib/systemd/system-shutdown/</filename></para>
37 <title>Description</title>
39 <para><filename>systemd-poweroff.service</filename> is a system service that is pulled in by
40 <filename>poweroff.target</filename> and is responsible for the actual system power-off
41 operation. Similarly, <filename>systemd-halt.service</filename> is pulled in by
42 <filename>halt.target</filename>, <filename>systemd-reboot.service</filename> by
43 <filename>reboot.target</filename> and <filename>systemd-kexec.service</filename> by
44 <filename>kexec.target</filename> to execute the respective actions.</para>
46 <para>When these services are run, they ensure that PID 1 is replaced by the
47 <filename>/usr/lib/systemd/systemd-shutdown</filename> tool which is then responsible for the actual
48 shutdown. Before shutting down, this binary will try to unmount all remaining file systems (or at least
49 remount them read-only), disable all remaining swap devices, detach all remaining storage devices and
50 kill all remaining processes.</para>
52 <para>It is necessary to have this code in a separate binary because otherwise rebooting after an upgrade
53 might be broken — the running PID 1 could still depend on libraries which are not available any more,
54 thus keeping the file system busy, which then cannot be re-mounted read-only.</para>
56 <para>Shortly before executing the actual system power-off/halt/reboot/kexec
57 <filename>systemd-shutdown</filename> will run all executables in
58 <filename>/usr/lib/systemd/system-shutdown/</filename> and pass one arguments to them: either
59 <literal>poweroff</literal>, <literal>halt</literal>, <literal>reboot</literal>, or
60 <literal>kexec</literal>, depending on the chosen action. All executables in this directory are executed
61 in parallel, and execution of the action is not continued before all executables finished. Note that
62 these executables are run <emphasis>after</emphasis> all services have been shut down, and after most
63 mounts have been unmounted (the root file system as well as <filename>/run/</filename> and various API
64 file systems are still around though). This means any programs dropped into this directory must be
65 prepared to run in such a limited execution environment and not rely on external services or hierarchies
66 such as <filename>/var/</filename> to be around (or writable).</para>
68 <para>Note that <filename>systemd-poweroff.service</filename> (and the related units) should never be
69 executed directly. Instead, trigger system shutdown with a command such as <literal>systemctl
70 poweroff</literal>.</para>
72 <para>Another form of shutdown is provided by the
73 <citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
74 functionality. It reboots only the OS userspace, leaving the kernel, firmware, and hardware as it is.</para>
78 <title>See Also</title>
80 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
81 <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
82 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
83 <citerefentry><refentrytitle>reboot</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
84 <citerefentry><refentrytitle>systemd-suspend.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
85 <citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
86 <citerefentry><refentrytitle>bootup</refentrytitle><manvolnum>7</manvolnum></citerefentry>