diff --git a/tuned/daemon/application.py b/tuned/daemon/application.py index db2ba34..618d1ce 100644 --- a/tuned/daemon/application.py +++ b/tuned/daemon/application.py @@ -186,9 +186,7 @@ class Application(object): # override global config if ran from command line with daemon option (-d) if daemon: self.config.set(consts.CFG_DAEMON, True) - if self.config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON): - exports.start() - else: + if not self.config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON): log.warn("Using one shot no deamon mode, most of the functionality will be not available, it can be changed in global config") result = self._controller.run() if self.config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON): diff --git a/tuned/daemon/controller.py b/tuned/daemon/controller.py index 59a55b1..c0adb75 100644 --- a/tuned/daemon/controller.py +++ b/tuned/daemon/controller.py @@ -28,9 +28,12 @@ class Controller(tuned.exports.interfaces.ExportableInterface): Controller main loop. The call is blocking. """ log.info("starting controller") - self.start() + res = self.start() + daemon = self._global_config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON) + if not res and daemon: + exports.start() - if self._global_config.get_bool(consts.CFG_DAEMON, consts.CFG_DEF_DAEMON): + if daemon: self._terminate.clear() # we have to pass some timeout, otherwise signals will not work while not self._cmd.wait(self._terminate, 3600): diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py index 58d1340..f3a175e 100644 --- a/tuned/daemon/daemon.py +++ b/tuned/daemon/daemon.py @@ -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 +from tuned import exports import re log = tuned.logs.get() @@ -127,6 +128,8 @@ class Daemon(object): self._unit_manager.start_tuning() self._profile_applied.set() log.info("static tuning from profile '%s' applied" % self._profile.name) + if self._daemon: + exports.start() self._notify_profile_changed(self._profile.name, True, "OK") if self._daemon: diff --git a/tuned/exports/dbus_exporter.py b/tuned/exports/dbus_exporter.py index 65ee969..959275e 100644 --- a/tuned/exports/dbus_exporter.py +++ b/tuned/exports/dbus_exporter.py @@ -56,6 +56,9 @@ class DBusExporter(interfaces.ExporterInterface): def object_name(self): return self._object_name + def running(self): + return self._thread is not None + def export(self, method, in_signature, out_signature): if not inspect.ismethod(method): raise Exception("Only bound methods can be exported.") @@ -129,6 +132,8 @@ class DBusExporter(interfaces.ExporterInterface): self._dbus_object_cls = cls def start(self): + if self.running(): + return if self._dbus_object_cls is None: self._construct_dbus_object_class()