1
0
Fork 0

moved profile autodetection from post install script to tuned daemon

The file system image containing tuned can be prepared offline, thus we
need to check the configuration on the first run. This is also more
clean solution than the previous post install hack.

Resolves: rhbz#1144067

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2014-09-19 13:32:59 +02:00
parent d01e045fbd
commit 6c45d00656
2 changed files with 23 additions and 12 deletions

View file

@ -80,14 +80,6 @@ sed -i 's/\(dynamic_tuning[ \t]*=[ \t]*\).*/\10/' %{buildroot}%{_sysconfdir}/tun
%post
%systemd_post tuned.service
# try to autodetect the best profile for the system in case there is none preset
if [ ! -f /etc/tuned/active_profile -o -z "`cat /etc/tuned/active_profile 2>/dev/null`" ]
then
PROFILE=`/usr/sbin/tuned-adm recommend 2>/dev/null`
[ "$PROFILE" ] || PROFILE=balanced
/usr/sbin/tuned-adm profile "$PROFILE" 2>/dev/null || echo -n "$PROFILE" > /etc/tuned/active_profile
fi
# convert active_profile from full path to name (if needed)
sed -i 's|.*/\([^/]\+\)/[^\.]\+\.conf|\1|' /etc/tuned/active_profile

View file

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