1
0
Fork 0

Store current profile into /etc/tuned/active_profile and read it on SIGHUP fromt here

This commit is contained in:
Jan Kaluza 2012-03-08 10:20:22 +01:00
parent f640211e92
commit d3958b948d
3 changed files with 33 additions and 2 deletions

View file

@ -70,7 +70,7 @@ if __name__ == "__main__":
controller = tuned.Controller(config_file, debug)
tuned.utils.handle_signal(signal.SIGHUP, controller.reload)
tuned.utils.handle_signal(signal.SIGHUP, controller.switch_to_default_profile)
tuned.utils.handle_signal([signal.SIGINT, signal.SIGTERM], controller.terminate)
if daemon:

View file

@ -45,6 +45,8 @@ class Controller(exports.interfaces.ExportableInterface):
self._terminate = threading.Event()
if config_file:
self.config_file = config_file
else:
self.config_file = self.get_default_profile()
def run(self):
"""
@ -66,6 +68,24 @@ class Controller(exports.interfaces.ExportableInterface):
def terminate(self):
self._terminate.set()
def get_default_profile(self):
try:
with open("/etc/tuned/active_profile", "r") as f:
profile = f.read()
if not profile.startswith("/"):
profile = "/usr/lib/tuned/%s/tuned.conf" % (profile)
return profile
except (OSError,IOError,EOFError) as e:
log.error("Cannot read active profile from /etc/tuned/active_profile: %s" % (e))
return ""
def switch_to_default_profile(self):
profile = self.get_default_profile()
if len(profile) != 0:
return switch_profile(profile)
return False
@property
def config_file(self):
return self._config_file
@ -100,7 +120,9 @@ class Controller(exports.interfaces.ExportableInterface):
@exports.export("s", "b")
def switch_profile(self, profile):
cfg = "/usr/lib/tuned/%s/tuned.conf" % (profile)
cfg = profile
if not profile.startswith("/"):
cfg = "/usr/lib/tuned/%s/tuned.conf" % (profile)
try:
self.config_file = cfg
except ValueError as e:

View file

@ -50,6 +50,8 @@ class Daemon(object):
self._profile = profile.Profile(manager, self._config_file)
self._profile.load()
self.save_active_profile()
while not self._terminate.wait(10):
log.debug("updating monitors")
monitors_repo.update()
@ -59,6 +61,13 @@ class Daemon(object):
manager.delete_all()
tuned.utils.storage.Storage.get_instance().cleanup()
def save_active_profile(self):
try:
with open("/etc/tuned/active_profile", "w") as f:
f.write(self._config_file)
except (OSError,IOError) as e:
log.error("Cannot write active profile into /etc/tuned/active_profile: %s" % (e))
@property
def config_file(self):
return self._config_file