mirror of
https://github.com/systemd/systemd
synced 2024-10-15 20:45:09 +00:00
Merge pull request #29626 from bluca/auto_soft_reboot
systemctl: automatically softreboot/kexec if set up on reboot
This commit is contained in:
commit
f455365031
|
@ -136,6 +136,13 @@ All tools:
|
||||||
|
|
||||||
* `$SYSTEMCTL_SKIP_SYSV=1` — if set, do not call SysV compatibility hooks.
|
* `$SYSTEMCTL_SKIP_SYSV=1` — if set, do not call SysV compatibility hooks.
|
||||||
|
|
||||||
|
* `$SYSTEMCTL_SKIP_AUTO_KEXEC=1` — if set, do not automatically kexec instead of
|
||||||
|
reboot when a new kernel has been loaded.
|
||||||
|
|
||||||
|
* `$SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT=1` — if set, do not automatically soft-reboot
|
||||||
|
instead of reboot when a new root file system has been loaded in
|
||||||
|
`/run/nextroot`.
|
||||||
|
|
||||||
`systemd-nspawn`:
|
`systemd-nspawn`:
|
||||||
|
|
||||||
* `$SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=1` — if set, force `systemd-nspawn` into
|
* `$SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=1` — if set, force `systemd-nspawn` into
|
||||||
|
|
|
@ -595,16 +595,20 @@ node /org/freedesktop/login1 {
|
||||||
<function>SuspendThenHibernateWithFlags()</function> add <varname>flags</varname> to allow for
|
<function>SuspendThenHibernateWithFlags()</function> add <varname>flags</varname> to allow for
|
||||||
extendability, defined as follows:</para>
|
extendability, defined as follows:</para>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0)
|
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0)
|
||||||
#define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1)
|
#define SD_LOGIND_KEXEC_REBOOT (UINT64_C(1) << 1)
|
||||||
#define SD_LOGIND_SOFT_REBOOT (UINT64_C(1) << 2)
|
#define SD_LOGIND_SOFT_REBOOT (UINT64_C(1) << 2)
|
||||||
|
#define SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP (UINT64_C(1) << 3)
|
||||||
</programlisting>
|
</programlisting>
|
||||||
<para>When the <varname>flags</varname> is 0 then these methods behave just like the versions without
|
<para>When the <varname>flags</varname> is 0 then these methods behave just like the versions without
|
||||||
flags. When <constant>SD_LOGIND_ROOT_CHECK_INHIBITORS</constant> (0x01) is set, active inhibitors are
|
flags. When <constant>SD_LOGIND_ROOT_CHECK_INHIBITORS</constant> (0x01) is set, active inhibitors are
|
||||||
honoured for privileged users too. When <constant>SD_LOGIND_KEXEC_REBOOT</constant> (0x02) is set, then
|
honoured for privileged users too. When <constant>SD_LOGIND_KEXEC_REBOOT</constant> (0x02) is set,
|
||||||
<function>RebootWithFlags()</function> performs a kexec reboot if kexec kernel is loaded. When
|
then <function>RebootWithFlags()</function> performs a kexec reboot if kexec kernel is loaded. When
|
||||||
<constant>SD_LOGIND_SOFT_REBOOT</constant> (0x04) is set, then <function>RebootWithFlags()</function>
|
<constant>SD_LOGIND_SOFT_REBOOT</constant> (0x04) is set, or
|
||||||
performs a userspace reboot only.</para>
|
<constant>SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP</constant> (0x08) is set and a new root file system
|
||||||
|
has been set up on <literal>/run/nextroot/</literal>, then <function>RebootWithFlags()</function>
|
||||||
|
performs a userspace reboot only. <constant>SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP</constant> and
|
||||||
|
<constant>SD_LOGIND_KEXEC_REBOOT</constant> can be combined, with soft-reboot having precedence.</para>
|
||||||
|
|
||||||
<para><function>SetRebootParameter()</function> sets a parameter for a subsequent reboot operation.
|
<para><function>SetRebootParameter()</function> sets a parameter for a subsequent reboot operation.
|
||||||
See the description of <command>reboot</command> in
|
See the description of <command>reboot</command> in
|
||||||
|
|
|
@ -1652,6 +1652,13 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
|
||||||
<para>This command honors <option>--force</option> and <option>--when=</option> in a similar way
|
<para>This command honors <option>--force</option> and <option>--when=</option> in a similar way
|
||||||
as <command>halt</command>.</para>
|
as <command>halt</command>.</para>
|
||||||
|
|
||||||
|
<para>If a new kernel has been loaded via <command>kexec --load</command>, a
|
||||||
|
<command>kexec</command> will be performed instead of a reboot, unless
|
||||||
|
<literal>SYSTEMCTL_SKIP_AUTO_KEXEC=1</literal> has been set. If a new root file system has
|
||||||
|
been setup on <literal>/run/nextroot</literal>, a <command>soft-reboot</command> will be
|
||||||
|
performed instead of a reboot, unless <literal>SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT=1</literal> has
|
||||||
|
been set.</para>
|
||||||
|
|
||||||
<xi:include href="version-info.xml" xpointer="v246"/>
|
<xi:include href="version-info.xml" xpointer="v246"/>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -1681,6 +1688,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
|
||||||
|
|
||||||
<para>This command honors <option>--force</option> and <option>--when=</option> similarly
|
<para>This command honors <option>--force</option> and <option>--when=</option> similarly
|
||||||
to <command>halt</command>.</para>
|
to <command>halt</command>.</para>
|
||||||
|
|
||||||
|
<para>If a new kernel has been loaded via <command>kexec --load</command>, a
|
||||||
|
<command>kexec</command> will be performed when <command>reboot</command> is invoked, unless
|
||||||
|
<literal>SYSTEMCTL_SKIP_AUTO_KEXEC=1</literal> has been set.</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
@ -1700,6 +1711,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
|
||||||
<citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
<citerefentry><refentrytitle>systemd-soft-reboot.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
|
||||||
for details.</para>
|
for details.</para>
|
||||||
|
|
||||||
|
<para>If a new root file system has been setup on <literal>/run/nextroot</literal>, a
|
||||||
|
<command>soft-reboot</command> will be performed when <command>reboot</command> is invoked,
|
||||||
|
unless <literal>SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT=1</literal> has been set.</para>
|
||||||
|
|
||||||
<xi:include href="version-info.xml" xpointer="v254"/>
|
<xi:include href="version-info.xml" xpointer="v254"/>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<literal>handle-suspend-key</literal>,
|
<literal>handle-suspend-key</literal>,
|
||||||
<literal>handle-hibernate-key</literal>,
|
<literal>handle-hibernate-key</literal>,
|
||||||
<literal>handle-lid-switch</literal>,
|
<literal>handle-lid-switch</literal>,
|
||||||
for inhibiting reboot/power-off/halt/kexec,
|
for inhibiting reboot/power-off/halt/kexec/soft-reboot,
|
||||||
suspending/hibernating, the automatic idle detection, or the
|
suspending/hibernating, the automatic idle detection, or the
|
||||||
low-level handling of the power/sleep key and the lid switch,
|
low-level handling of the power/sleep key and the lid switch,
|
||||||
respectively. If omitted, defaults to
|
respectively. If omitted, defaults to
|
||||||
|
|
|
@ -164,6 +164,10 @@ ExecStart=sleep infinity
|
||||||
<para>Note that <filename>systemd-soft-reboot.service</filename> (and related units) should never be
|
<para>Note that <filename>systemd-soft-reboot.service</filename> (and related units) should never be
|
||||||
executed directly. Instead, trigger system shutdown with a command such as <literal>systemctl
|
executed directly. Instead, trigger system shutdown with a command such as <literal>systemctl
|
||||||
soft-reboot</literal>.</para>
|
soft-reboot</literal>.</para>
|
||||||
|
|
||||||
|
<para>Note that if a new root file system has been setup on <literal>/run/nextroot</literal>, a
|
||||||
|
<command>soft-reboot</command> will be performed when the <command>reboot</command> command is
|
||||||
|
invoked.</para>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
|
|
|
@ -7,11 +7,12 @@
|
||||||
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0)
|
#define SD_LOGIND_ROOT_CHECK_INHIBITORS (UINT64_C(1) << 0)
|
||||||
#define SD_LOGIND_REBOOT_VIA_KEXEC (UINT64_C(1) << 1)
|
#define SD_LOGIND_REBOOT_VIA_KEXEC (UINT64_C(1) << 1)
|
||||||
#define SD_LOGIND_SOFT_REBOOT (UINT64_C(1) << 2)
|
#define SD_LOGIND_SOFT_REBOOT (UINT64_C(1) << 2)
|
||||||
|
#define SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP (UINT64_C(1) << 3)
|
||||||
|
|
||||||
/* For internal use only */
|
/* For internal use only */
|
||||||
#define SD_LOGIND_INTERACTIVE (UINT64_C(1) << 63)
|
#define SD_LOGIND_INTERACTIVE (UINT64_C(1) << 63)
|
||||||
|
|
||||||
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_REBOOT_VIA_KEXEC|SD_LOGIND_SOFT_REBOOT)
|
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC (SD_LOGIND_ROOT_CHECK_INHIBITORS|SD_LOGIND_REBOOT_VIA_KEXEC|SD_LOGIND_SOFT_REBOOT|SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP)
|
||||||
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC|SD_LOGIND_INTERACTIVE)
|
#define SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_ALL (SD_LOGIND_SHUTDOWN_AND_SLEEP_FLAGS_PUBLIC|SD_LOGIND_INTERACTIVE)
|
||||||
|
|
||||||
bool session_id_valid(const char *id);
|
bool session_id_valid(const char *id);
|
||||||
|
|
|
@ -1895,7 +1895,7 @@ static int method_do_shutdown_or_sleep(
|
||||||
if (flags & SD_LOGIND_REBOOT_VIA_KEXEC)
|
if (flags & SD_LOGIND_REBOOT_VIA_KEXEC)
|
||||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
|
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||||
"Reboot via kexec option is only applicable with reboot operations");
|
"Reboot via kexec option is only applicable with reboot operations");
|
||||||
if (flags & SD_LOGIND_SOFT_REBOOT)
|
if ((flags & SD_LOGIND_SOFT_REBOOT) || (flags & SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP))
|
||||||
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
|
return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS,
|
||||||
"Soft reboot option is only applicable with reboot operations");
|
"Soft reboot option is only applicable with reboot operations");
|
||||||
}
|
}
|
||||||
|
@ -1912,10 +1912,11 @@ static int method_do_shutdown_or_sleep(
|
||||||
flags = interactive ? SD_LOGIND_INTERACTIVE : 0;
|
flags = interactive ? SD_LOGIND_INTERACTIVE : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & SD_LOGIND_REBOOT_VIA_KEXEC) && kexec_loaded())
|
if ((flags & SD_LOGIND_SOFT_REBOOT) ||
|
||||||
a = handle_action_lookup(HANDLE_KEXEC);
|
((flags & SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP) && path_is_os_tree("/run/nextroot") > 0))
|
||||||
else if ((flags & SD_LOGIND_SOFT_REBOOT))
|
|
||||||
a = handle_action_lookup(HANDLE_SOFT_REBOOT);
|
a = handle_action_lookup(HANDLE_SOFT_REBOOT);
|
||||||
|
else if ((flags & SD_LOGIND_REBOOT_VIA_KEXEC) && kexec_loaded())
|
||||||
|
a = handle_action_lookup(HANDLE_KEXEC);
|
||||||
|
|
||||||
/* Don't allow multiple jobs being executed at the same time */
|
/* Don't allow multiple jobs being executed at the same time */
|
||||||
if (m->delayed_action)
|
if (m->delayed_action)
|
||||||
|
|
|
@ -80,7 +80,12 @@ int logind_reboot(enum action a) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
SET_FLAG(flags, SD_LOGIND_ROOT_CHECK_INHIBITORS, arg_check_inhibitors > 0);
|
SET_FLAG(flags, SD_LOGIND_ROOT_CHECK_INHIBITORS, arg_check_inhibitors > 0);
|
||||||
SET_FLAG(flags, SD_LOGIND_REBOOT_VIA_KEXEC, a == ACTION_KEXEC);
|
SET_FLAG(flags,
|
||||||
|
SD_LOGIND_REBOOT_VIA_KEXEC,
|
||||||
|
a == ACTION_KEXEC || (a == ACTION_REBOOT && getenv_bool("SYSTEMCTL_SKIP_AUTO_KEXEC") <= 0));
|
||||||
|
SET_FLAG(flags,
|
||||||
|
SD_LOGIND_SOFT_REBOOT_IF_NEXTROOT_SET_UP,
|
||||||
|
a == ACTION_REBOOT && getenv_bool("SYSTEMCTL_SKIP_AUTO_SOFT_REBOOT") <= 0);
|
||||||
SET_FLAG(flags, SD_LOGIND_SOFT_REBOOT, a == ACTION_SOFT_REBOOT);
|
SET_FLAG(flags, SD_LOGIND_SOFT_REBOOT, a == ACTION_SOFT_REBOOT);
|
||||||
|
|
||||||
r = bus_call_method(bus, bus_login_mgr, method_with_flags, &error, NULL, "t", flags);
|
r = bus_call_method(bus, bus_login_mgr, method_with_flags, &error, NULL, "t", flags);
|
||||||
|
|
|
@ -1090,10 +1090,7 @@ int systemctl_dispatch_parse_argv(int argc, char *argv[]) {
|
||||||
return halt_parse_argv(argc, argv);
|
return halt_parse_argv(argc, argv);
|
||||||
|
|
||||||
} else if (invoked_as(argv, "reboot")) {
|
} else if (invoked_as(argv, "reboot")) {
|
||||||
if (kexec_loaded())
|
arg_action = ACTION_REBOOT;
|
||||||
arg_action = ACTION_KEXEC;
|
|
||||||
else
|
|
||||||
arg_action = ACTION_REBOOT;
|
|
||||||
return halt_parse_argv(argc, argv);
|
return halt_parse_argv(argc, argv);
|
||||||
|
|
||||||
} else if (invoked_as(argv, "shutdown")) {
|
} else if (invoked_as(argv, "shutdown")) {
|
||||||
|
|
|
@ -133,9 +133,10 @@ elif [ -f /run/testsuite82.touch ]; then
|
||||||
# Restart the unit that is not supposed to survive
|
# Restart the unit that is not supposed to survive
|
||||||
systemd-run --collect --service-type=exec --unit=testsuite-82-nosurvive.service sleep infinity
|
systemd-run --collect --service-type=exec --unit=testsuite-82-nosurvive.service sleep infinity
|
||||||
|
|
||||||
# Now issue the soft reboot. We should be right back soon.
|
# Now issue the soft reboot. We should be right back soon. Given /run/nextroot exists, we should
|
||||||
|
# automatically do a softreboot instead of normal reboot.
|
||||||
touch /run/testsuite82.touch2
|
touch /run/testsuite82.touch2
|
||||||
systemctl --no-block soft-reboot
|
systemctl --no-block reboot
|
||||||
|
|
||||||
# Now block until the soft-boot killing spree kills us
|
# Now block until the soft-boot killing spree kills us
|
||||||
exec sleep infinity
|
exec sleep infinity
|
||||||
|
|
Loading…
Reference in a new issue