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:
parent
bfab9d8d22
commit
701f09a89d
2 changed files with 14 additions and 8 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[Unit]
|
||||
Description=Dynamic System Tuning Daemon
|
||||
After=systemd-sysctl.service network.target
|
||||
After=systemd-sysctl.service network.target dbus.service
|
||||
Requires=dbus.service polkit.service
|
||||
Conflicts=cpupower.service
|
||||
Documentation=man:tuned(8) man:tuned.conf(5) man:tuned-adm(8)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from tuned.exceptions import TunedException
|
|||
from tuned.profiles.exceptions import InvalidProfileException
|
||||
import tuned.consts as consts
|
||||
from tuned.utils.commands import commands
|
||||
import re
|
||||
|
||||
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)
|
||||
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):
|
||||
if self._profile is None:
|
||||
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
|
||||
# do full cleanup
|
||||
full_rollback = False
|
||||
retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
|
||||
if retcode >= 0:
|
||||
if out[:8] == "stopping":
|
||||
log.info("terminating Tuned due to system shutdown / reboot")
|
||||
else:
|
||||
log.info("terminating Tuned, rolling back all changes")
|
||||
full_rollback = True
|
||||
if self._system_shutting_down():
|
||||
log.info("terminating Tuned due to system shutdown / reboot")
|
||||
else:
|
||||
log.info("terminating Tuned, rolling back all changes")
|
||||
full_rollback = True
|
||||
if self._daemon:
|
||||
self._unit_manager.stop_tuning(full_rollback)
|
||||
self._unit_manager.destroy_all()
|
||||
|
|
|
|||
Loading…
Reference in a new issue