|
|
4fe94b |
diff --git a/tuned/daemon/daemon.py b/tuned/daemon/daemon.py
|
|
|
4fe94b |
index 35f60c2..029e311 100644
|
|
|
4fe94b |
--- a/tuned/daemon/daemon.py
|
|
|
4fe94b |
+++ b/tuned/daemon/daemon.py
|
|
|
4fe94b |
@@ -1,4 +1,5 @@
|
|
|
4fe94b |
import os
|
|
|
4fe94b |
+import errno
|
|
|
4fe94b |
import threading
|
|
|
4fe94b |
import tuned.logs
|
|
|
4fe94b |
from tuned.exceptions import TunedException
|
|
|
4fe94b |
@@ -105,16 +106,34 @@ class Daemon(object):
|
|
|
4fe94b |
def _save_active_profile(self, profile_name):
|
|
|
4fe94b |
try:
|
|
|
4fe94b |
with open(consts.ACTIVE_PROFILE_FILE, "w") as f:
|
|
|
4fe94b |
- f.write(profile_name)
|
|
|
4fe94b |
+ f.write(profile_name + "\n")
|
|
|
4fe94b |
except (OSError,IOError) as e:
|
|
|
4fe94b |
log.error("Cannot write active profile into %s: %s" % (consts.ACTIVE_PROFILE_FILE, str(e)))
|
|
|
4fe94b |
|
|
|
4fe94b |
+ def _set_recommended_profile(self):
|
|
|
4fe94b |
+ log.info("no profile preset, checking what is recommended for your configuration")
|
|
|
4fe94b |
+ profile = tuned.utils.commands.recommend_profile()
|
|
|
4fe94b |
+ log.info("using '%s' profile and setting it as active" % profile)
|
|
|
4fe94b |
+ self._save_active_profile(profile)
|
|
|
4fe94b |
+ return profile
|
|
|
4fe94b |
+
|
|
|
4fe94b |
def _get_active_profile(self):
|
|
|
4fe94b |
try:
|
|
|
4fe94b |
with open(consts.ACTIVE_PROFILE_FILE, "r") as f:
|
|
|
4fe94b |
- return f.read().strip()
|
|
|
4fe94b |
- except (OSError, IOError, EOFError) as e:
|
|
|
4fe94b |
- log.error("Cannot read active profile, setting default.")
|
|
|
4fe94b |
+ profile = f.read().strip()
|
|
|
4fe94b |
+ if profile == "":
|
|
|
4fe94b |
+ profile = self._set_recommended_profile()
|
|
|
4fe94b |
+ return profile
|
|
|
4fe94b |
+ except IOError as e:
|
|
|
4fe94b |
+ if e.errno == errno.ENOENT:
|
|
|
4fe94b |
+ # No such file or directory
|
|
|
4fe94b |
+ profile = self._set_recommended_profile()
|
|
|
4fe94b |
+ else:
|
|
|
4fe94b |
+ profile = consts.DEFAULT_PROFILE
|
|
|
4fe94b |
+ log.error("error reading active profile from '%s', falling back to '%s' profile" % (consts.ACTIVE_PROFILE_FILE, profile))
|
|
|
4fe94b |
+ return profile
|
|
|
4fe94b |
+ except (OSError, EOFError) as e:
|
|
|
4fe94b |
+ log.error("cannot read active profile, falling back to '%s' profile" % consts.DEFAULT_PROFILE)
|
|
|
4fe94b |
return consts.DEFAULT_PROFILE
|
|
|
4fe94b |
|
|
|
4fe94b |
def is_enabled(self):
|