Blame SOURCES/tuned-2.8.0-improve-reboot-check.patch

0208af
diff --git a/tuned.service b/tuned.service
0208af
index fcb3fa0..c59e3a9 100644
0208af
--- a/tuned.service
0208af
+++ b/tuned.service
0208af
@@ -1,6 +1,6 @@
0208af
 [Unit]
0208af
 Description=Dynamic System Tuning Daemon
0208af
-After=syslog.target systemd-sysctl.service network.target
0208af
+After=syslog.target systemd-sysctl.service network.target dbus.service
0208af
 Requires=dbus.service polkit.service
0208af
 Conflicts=cpupower.service
0208af
 
0208af
diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py
0208af
index b7db721..f78ec5a 100644
0208af
--- a/tuned/daemon/daemon.py
0208af
+++ b/tuned/daemon/daemon.py
0208af
@@ -6,6 +6,7 @@ from tuned.exceptions import TunedException
0208af
 from tuned.profiles.exceptions import InvalidProfileException
0208af
 import tuned.consts as consts
0208af
 from tuned.utils.commands import commands
0208af
+import re
0208af
 
0208af
 log = tuned.logs.get()
0208af
 
0208af
@@ -98,6 +99,13 @@ class Daemon(object):
0208af
 			self._application._dbus_exporter.send_signal(consts.DBUS_SIGNAL_PROFILE_CHANGED, profile_name, result, errstr)
0208af
 		return errstr
0208af
 
0208af
+	def _system_shutting_down(self):
0208af
+		retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
0208af
+		if out[:8] == "stopping":
0208af
+			return True
0208af
+		retcode, out = self._cmd.execute(["systemctl", "list-jobs"], no_errors = [0])
0208af
+		return re.search(r"\b(shutdown|reboot|halt|poweroff)\.target.*start", out) is not None
0208af
+
0208af
 	def _thread_code(self):
0208af
 		if self._profile is None:
0208af
 			raise TunedException("Cannot start the daemon without setting a profile.")
0208af
@@ -143,13 +151,11 @@ class Daemon(object):
0208af
 			# stopped by user and in such case do full cleanup, without systemd never
0208af
 			# do full cleanup
0208af
 			full_rollback = False
0208af
-			retcode, out = self._cmd.execute(["systemctl", "is-system-running"], no_errors = [0])
0208af
-			if retcode >= 0:
0208af
-				if out[:8] == "stopping":
0208af
-					log.info("terminating Tuned due to system shutdown / reboot")
0208af
-				else:
0208af
-					log.info("terminating Tuned, rolling back all changes")
0208af
-					full_rollback = True
0208af
+			if self._system_shutting_down():
0208af
+				log.info("terminating Tuned due to system shutdown / reboot")
0208af
+			else:
0208af
+				log.info("terminating Tuned, rolling back all changes")
0208af
+				full_rollback = True
0208af
 		if self._daemon:
0208af
 			self._unit_manager.stop_tuning(full_rollback)
0208af
 		self._unit_manager.destroy_all()