1
0
Fork 0

tuned-adm: active: detect whether tuned deamon is running

Related: rhbz#1068699

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2014-09-24 19:17:25 +02:00
parent cd506bdf57
commit 53118d60cb

View file

@ -2,7 +2,9 @@ from tuned.utils.commands import commands
from tuned.profiles import Locator as profiles_locator
from exceptions import TunedAdminDBusException
import tuned.consts as consts
import os
import sys
import errno
class Admin(object):
def __init__(self, controller, debug = False):
@ -13,6 +15,15 @@ class Admin(object):
def _error(self, message):
print >>sys.stderr, message
def _tuned_is_running(self):
try:
os.kill(int(self._cmd.read_file(consts.PID_FILE)), 0)
except OSError as e:
return e.errno == errno.EPERM
except (ValueError, IOError) as e:
return False
return True
def list(self):
try:
profile_names = self._controller.profiles()
@ -29,9 +40,13 @@ class Admin(object):
profile_name = self._controller.active_profile()
except TunedAdminDBusException as e:
self._error(e)
profile_name = self._cmd.read_file(consts.ACTIVE_PROFILE_FILE, None)
profile_name = str.strip(self._cmd.read_file(consts.ACTIVE_PROFILE_FILE, None))
if profile_name is not None and profile_name != "":
print "Current active profile: %s" % profile_name
if self._tuned_is_running():
print "Current active profile: %s" % profile_name
else:
print "It seems that tuned daemon is not running, preset profile is not activated."
print "Preset profile: %s" % profile_name
return True
else:
print "No current active profile."