diff --git a/commands/__init__.py b/commands/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/commands/cmd_list.py b/commands/cmd_list.py deleted file mode 100644 index 2f71a1f..0000000 --- a/commands/cmd_list.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import os.path -import glob -import kobo.shortcuts -from kobo.cli import Command - -class List(Command): - """list all available profiles""" - enabled = True - - def options(self): - self.parser.usage = "%%prog %s" % self.normalized_name - - self.parser.add_option( - "--show-disabled", - default=False, - action="store_true", - help="show disabled workers" - ) - - - def run(self, *args, **kwargs): - # link config files into directory which is exectued by ktune - if os.path.exists("/etc/tune-profiles/"): - modes = os.listdir("/etc/tune-profiles") - if len(modes) > 0: - print "Modes: " - for i in range(len(modes)): - print modes[i] - else: - print "No other profiles than default defined." diff --git a/commands/cmd_off_mode.py b/commands/cmd_off_mode.py deleted file mode 100644 index 779ac50..0000000 --- a/commands/cmd_off_mode.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import glob -import kobo.shortcuts -from kobo.cli import Command - -class Off(Command): - """switch off all tunning""" - enabled = True - - def options(self): - self.parser.usage = "%%prog %s" % self.normalized_name - - self.parser.add_option( - "--show-disabled", - default=False, - action="store_true", - help="show disabled workers" - ) - - - def run(self, *args, **kwargs): - os.system("rm -rf /etc/ktune.d/*.conf") - os.system("rm -rf /etc/ktune.d/*.sh") - if os.path.exists("/etc/sysconfig/ktune.bckp"): - os.rename("/etc/sysconfig/ktune.bckp", "/etc/sysconfig/ktune") - if os.path.exists("/etc/tuned.conf.bckp") and os.path.exists("/etc/tuned.conf"): - os.rename("/etc/tuned.conf.bckp", "/etc/tuned.conf") - os.system('service ktune stop') - os.system('service tuned stop') - os.system('chkconfig --del ktune') - os.system('chkconfig --del tuned') diff --git a/commands/cmd_profile.py b/commands/cmd_profile.py deleted file mode 100644 index 96cc0f5..0000000 --- a/commands/cmd_profile.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import os.path -import glob -import kobo.shortcuts -from kobo.cli import Command - -class Profile(Command): - """ switch to given profile""" - enabled = True - - def options(self): - self.parser.usage = "%%prog %s" % self.normalized_name - - self.parser.add_option( - "--show-disabled", - default=False, - action="store_true", - help="show disabled workers" - ) - - - def run(self, *args, **kwargs): - # link config files into directory which is exectued by ktune - enablektune = False - enabletuned = False - if len(args) == 0: - print "No profile given. To list all available profiles please run:" - print "tuned-adm list" - return - if not os.path.exists("/etc/tune-profiles/"+args[0]): - print "No profile with name %s found." % args[0] - return - if os.path.exists("/etc/tune-profiles/"): - os.system('service ktune stop') - os.system('chkconfig --add ktune && chkconfig --level 345 ktune off') - os.system('service tuned stop') - os.system('chkconfig --add tuned && chkconfig --level 345 tuned off') - modes = os.listdir("/etc/tune-profiles") - if modes > 0: - print 'Switching to profile %s' % args[0] - if os.path.exists('/etc/ktune.d/tunedadm.sh'): - os.remove('/etc/ktune.d/tunedadm.sh') - if os.path.exists('/etc/ktune.d/tunedadm.conf'): - os.remove('/etc/ktune.d/tunedadm.conf') - file = ('/etc/tune-profiles/%s/ktune.sysconfig' % args[0]) - if os.path.exists(file): - enablektune = True - os.rename('/etc/sysconfig/ktune', '/etc/sysconfig/ktune.bckp') - os.symlink(file, '/etc/sysconfig/ktune') - file = ('/etc/tune-profiles/%s/ktune.sh' % args[0]) - if os.path.exists(file): - os.symlink(file, '/etc/ktune.d/tunedadm.sh') - file = ('/etc/tune-profiles/%s/sysctl.ktune' % args[0]) - if os.path.exists(file): - os.symlink(file, '/etc/ktune.d/tunedadm.conf') - file = ('/etc/tune-profiles/%s/tuned.conf' % args[0]) - if os.path.exists(file): - enabletuned = True - os.rename('/etc/tuned.conf', '/etc/tuned.conf.bckp') - os.symlink(file, '/etc/tuned.conf') - - if enablektune: - os.system('service ktune start') - os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') - - if enabletuned: - os.system('service tuned start') - os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') diff --git a/tuned-adm b/tuned-adm index 7a4b511..eabd2ed 100755 --- a/tuned-adm +++ b/tuned-adm @@ -1,26 +1,76 @@ #!/usr/bin/python +# +# tuned-adm: A command line utility for switching between user +# definable tuning profiles. +# +# Copyright (C) 2008, 2009 Red Hat, Inc. +# Authors: Marcela Maslanova +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# import os import sys import locale -from kobo.cli import * +import getopt +def usage(): + print """ +Usage: tuned-adm [-p ] [-h] [args] +Options: + -p directory with profiles + -h, --help show this help message and exit -from kobo.tback import * -set_except_hook() - - -TUNEDDIR="/usr/share/tuned" -if TUNEDDIR not in sys.path: - sys.path.insert(0, TUNEDDIR) - -import commands -CommandContainer.register_module(commands) - - -def main(argv): - parser = CommandOptionParser(command_container=CommandContainer(), default_command="help") - parser.run() +commands: + list list all available profiles + off switch off all tunning + profile switch to given profile +""" if __name__ == "__main__": - main(sys.argv[1:]) + + profile_dir = "/etc/tune-profiles/" + + try: + opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help"]) + except getopt.error, e: + print >>sys.stderr, "Error parsing command-line arguments: %s" % e + usage() + sys.exit(1) + + for (opt, val) in opts: + if opt in ['-h', "--help"]: + usage() + sys.exit(0) + if opt in ['-p']: + profile_dir = val + + if len(args) < 1: + print >>sys.stderr, ("Missing arguments.") + usage() + sys.exit(1) + + TUNEDDIR="/usr/share/tuned" + if TUNEDDIR not in sys.path: + sys.path.insert(0, TUNEDDIR) + + from tuned_adm import tuned_adm + + tuned_adm.init(profile_dir) + if (tuned_adm.run(args)): + usage() + sys.exit(1) + + diff --git a/tuned.spec b/tuned.spec index 8410bd5..f6f44bd 100644 --- a/tuned.spec +++ b/tuned.spec @@ -1,7 +1,7 @@ Summary: A dynamic adaptive system tuning daemon Name: tuned -Version: 0.2.4 -Release: 2%{?dist} +Version: 0.2.5 +Release: 0.1%{?dist} License: GPLv2+ Group: System Environment/Daemons # The source for this package was pulled from upstream git. Use the @@ -18,7 +18,6 @@ Requires(preun): chkconfig Requires(preun): initscripts Requires(postun): initscripts BuildArch: noarch -Requires: kobo %description The tuned package contains a daemon that tunes system settings dynamically. @@ -97,6 +96,9 @@ fi %changelog +* Fri Oct 2 2009 Petr Lautrbach 0.2.5-0.1 +- tuned-adm without kobo dependence + * Wed Sep 23 2009 Petr Lautrbach 0.2.4-2 - fixed url to fedorahosted project page - Resolves: #519019 diff --git a/tuned_adm.py b/tuned_adm.py new file mode 100644 index 0000000..8001d13 --- /dev/null +++ b/tuned_adm.py @@ -0,0 +1,113 @@ +# Copyright (C) 2008, 2009 Red Hat, Inc. +# Authors: Phil Knirsch +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# + +import sys,os,glob + +class Tuned_adm: + def __init__(self): + self.profile_dir = "/etc/tune-profiles/" + + + def init(self, profile_dir): + self.profile_dir = profile_dir + + + def run(self, args): + if args[0] == "list": + self.list() + elif args[0] == "off": + self.off() + elif args[0] == "profile": + self.profile(args[1:]) + else: + print >>sys.stderr, "Nonexistent argument %s" % args[0] + return 1 + + + def list(self): + if os.path.exists(self.profile_dir): + modes = os.listdir(self.profile_dir) + if len(modes) > 0: + print "Modes: " + for i in range(len(modes)): + print modes[i] + else: + print "No profiles defined." + + def off(self): + os.system("rm -rf /etc/ktune.d/*.conf") + os.system("rm -rf /etc/ktune.d/*.sh") + if os.path.exists("/etc/sysconfig/ktune.bckp"): + os.rename("/etc/sysconfig/ktune.bckp", "/etc/sysconfig/ktune") + if os.path.exists("/etc/tuned.conf.bckp") and os.path.exists("/etc/tuned.conf"): + os.rename("/etc/tuned.conf.bckp", "/etc/tuned.conf") + os.system('service ktune stop') + os.system('service tuned stop') + os.system('chkconfig --del ktune') + os.system('chkconfig --del tuned') + + + def profile(self, args): + enablektune = False + enabletuned = False + if len(args) == 0: + print "No profile given. To list all available profiles please run:" + print "tuned-adm list" + return + if not os.path.exists(self.profile_dir+"/"+args[0]): + print "No profile with name %s found." % args[0] + return + if os.path.exists(self.profile_dir): + os.system('service ktune stop') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune off') + os.system('service tuned stop') + os.system('chkconfig --add tuned && chkconfig --level 345 tuned off') + modes = os.listdir(self.profile_dir) + if modes > 0: + print 'Switching to profile %s' % args[0] + if os.path.exists('/etc/ktune.d/tunedadm.sh'): + os.remove('/etc/ktune.d/tunedadm.sh') + if os.path.exists('/etc/ktune.d/tunedadm.conf'): + os.remove('/etc/ktune.d/tunedadm.conf') + file = ('%s/%s/ktune.sysconfig' % (self.profile_dir, args[0])) + if os.path.exists(file): + enablektune = True + os.rename('/etc/sysconfig/ktune', '/etc/sysconfig/ktune.bckp') + os.symlink(file, '/etc/sysconfig/ktune') + file = ('%s/%s/ktune.sh' % (self.profile_dir, args[0])) + if os.path.exists(file): + os.symlink(file, '/etc/ktune.d/tunedadm.sh') + file = ('%s/%s/sysctl.ktune' % (self.profile_dir, args[0])) + if os.path.exists(file): + os.symlink(file, '/etc/ktune.d/tunedadm.conf') + file = ('%s/%s/tuned.conf' % (self.profile_dir, args[0])) + if os.path.exists(file): + enabletuned = True + os.rename('/etc/tuned.conf', '/etc/tuned.conf.bckp') + os.symlink(file, '/etc/tuned.conf') + + if enablektune: + os.system('service ktune start') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') + + if enabletuned: + os.system('service tuned start') + os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') + + +tuned_adm = Tuned_adm()