1
0
Fork 0

Improve checking if we are rebooting or not

'systemctl is-system-running' is not enough to reliably check
if the system is shutting down. If the command is run when the system
is still starting up, it will report the state as 'starting', even if
the shutdown target is queued:
5463fa0a88/src/core/manager.c (L3457-L3465)

On the other hand, 'systemctl list-jobs' should always show
shutdown.target or reboot.target etc., when the system is shutting
down, as long as DBus is still running.

Resolves: rhbz#1475571
Resolves: rhbz#1488369
Resolves: rhbz#1488517

Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
This commit is contained in:
Ondřej Lysoněk 2017-09-07 17:44:27 +02:00
parent bfab9d8d22
commit 701f09a89d
2 changed files with 14 additions and 8 deletions

View file

@ -1,6 +1,6 @@
[Unit] [Unit]
Description=Dynamic System Tuning Daemon Description=Dynamic System Tuning Daemon
After=systemd-sysctl.service network.target After=systemd-sysctl.service network.target dbus.service
Requires=dbus.service polkit.service Requires=dbus.service polkit.service
Conflicts=cpupower.service Conflicts=cpupower.service
Documentation=man:tuned(8) man:tuned.conf(5) man:tuned-adm(8) Documentation=man:tuned(8) man:tuned.conf(5) man:tuned-adm(8)

View file

@ -6,6 +6,7 @@ from tuned.exceptions import TunedException
from tuned.profiles.exceptions import InvalidProfileException from tuned.profiles.exceptions import InvalidProfileException
import tuned.consts as consts import tuned.consts as consts
from tuned.utils.commands import commands from tuned.utils.commands import commands
import re
log = tuned.logs.get() log = tuned.logs.get()
@ -106,6 +107,13 @@ class Daemon(object):
self._application._dbus_exporter.send_signal(consts.DBUS_SIGNAL_PROFILE_CHANGED, profile_name, result, errstr) self._application._dbus_exporter.send_signal(consts.DBUS_SIGNAL_PROFILE_CHANGED, profile_name, result, errstr)
return errstr return errstr
def _system_shutting_down(self):
retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
if out[:8] == "stopping":
return True
retcode, out = self._cmd.execute(["systemctl", "list-jobs"], no_errors = [0])
return re.search(r"\b(shutdown|reboot|halt|poweroff)\.target.*start", out) is not None
def _thread_code(self): def _thread_code(self):
if self._profile is None: if self._profile is None:
raise TunedException("Cannot start the daemon without setting a profile.") raise TunedException("Cannot start the daemon without setting a profile.")
@ -151,13 +159,11 @@ class Daemon(object):
# stopped by user and in such case do full cleanup, without systemd never # stopped by user and in such case do full cleanup, without systemd never
# do full cleanup # do full cleanup
full_rollback = False full_rollback = False
retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0]) if self._system_shutting_down():
if retcode >= 0: log.info("terminating Tuned due to system shutdown / reboot")
if out[:8] == "stopping": else:
log.info("terminating Tuned due to system shutdown / reboot") log.info("terminating Tuned, rolling back all changes")
else: full_rollback = True
log.info("terminating Tuned, rolling back all changes")
full_rollback = True
if self._daemon: if self._daemon:
self._unit_manager.stop_tuning(full_rollback) self._unit_manager.stop_tuning(full_rollback)
self._unit_manager.destroy_all() self._unit_manager.destroy_all()