1
0
Fork 0

Change the config_file and reload the daemon when the profile is switched

This commit is contained in:
Jan Kaluza 2012-01-26 10:43:26 +01:00
parent 6d4a85e838
commit da0926bb6d
2 changed files with 33 additions and 9 deletions

View file

@ -41,7 +41,8 @@ class Controller(exports.interfaces.ExportableInterface):
def __init__(self, config_file, debug):
super(self.__class__, self).__init__()
exports.register_object(self)
self._daemon = daemon.Daemon(config_file)
self._config_file = config_file
self._daemon = daemon.Daemon()
self._terminate = threading.Event()
def run(self):
@ -89,8 +90,13 @@ class Controller(exports.interfaces.ExportableInterface):
@exports.export("s", "b")
def switch_profile(self, profile):
# TODO
return False
config_file = "/etc/tune-profiles/%s/tuned.conf" % (profile)
try:
self._daemon.config_file = config_file
except ValueError as e:
log.error("Unable to open profile's config file %s" % (config_file) )
return False
return self.reload()
@exports.export("", "s")
def active_profile(self):

View file

@ -15,27 +15,34 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
import os
import units
import utils
import logs
import monitors
import plugins
import threading
import ConfigParser
log = logs.get()
DEFAULT_CONFIG_FILE = "/etc/tuned/tuned.conf"
class Daemon(object):
def __init__(self, config_file = None):
def __init__(self):
log.info("initializing Daemon")
if config_file is None:
config_file = DEFAULT_CONFIG_FILE
self._config_file = config_file
self._config_file = DEFAULT_CONFIG_FILE
self._thread = None
self._terminate = threading.Event()
def _load_plugins(self, manager):
cfg = ConfigParser.SafeConfigParser()
cfg.read(self._config_file)
test_a = manager.create("test", "test", None)
test_b = manager.create("foo", "cpu", None)
def _thread_code(self):
self._terminate.clear()
@ -44,8 +51,7 @@ class Daemon(object):
monitors_repo = monitors.get_repository()
plugins_repo = plugins.get_repository()
test_a = manager.create("test", "test", None)
test_b = manager.create("foo", "cpu", None)
self._load_plugins(manager)
while not self._terminate.wait(10):
log.debug("updating monitors")
@ -55,6 +61,18 @@ class Daemon(object):
manager.delete_all()
@property
def config_file(self):
return self._config_file
@config_file.setter
def config_file(self, value):
if not os.path.exists(value):
raise ValueError("Config file does not exist")
self._config_file = value
# TODO: Maybe restart the daemon here?
def is_running(self):
return self._thread is not None and self._thread.is_alive()