diff --git a/Makefile b/Makefile index af359f1..d455e15 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ FILES_doc = doc/DESIGN.txt doc/README.utils doc/TIPS.txt doc/tuned.8 doc/tuned.c FILES_contrib = contrib/diskdevstat contrib/netdevstat contrib/scomes contrib/varnetload FILES_tuningplugins = tuningplugins/disk.py tuningplugins/net.py tuningplugins/__init__.py FILES_monitorplugins = monitorplugins/disk.py monitorplugins/net.py monitorplugins/__init__.py -FILES_commands = commands/cmd_default_mode.py commands/cmd_server_mode.py commands/cmd_off_mode.py commands/__init__.py +FILES_commands = commands/cmd_default_mode.py commands/cmd_off_mode.py commands/cmd_list.py \ + commands/cmd_modes.py commands/__init__.py DOCS = AUTHORS ChangeLog COPYING INSTALL NEWS README distarchive: tag archive @@ -81,7 +82,7 @@ install: mkdir -p $(DESTDIR)/etc install -m 0644 tuned.conf $(DESTDIR)/etc - mkdir -p $(DESTDIR)/etc/tune-profiles/{desktop,laptop,personal,server} + mkdir -p $(DESTDIR)/etc/tune-profiles/ # Install initscript mkdir -p $(DESTDIR)/etc/rc.d/init.d diff --git a/commands/cmd_default_mode.py b/commands/cmd_default_mode.py index 8bc270f..539a451 100644 --- a/commands/cmd_default_mode.py +++ b/commands/cmd_default_mode.py @@ -26,7 +26,7 @@ class Default(Command): os.system('service tuned start') os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') - usb_devices = glob.glob('/sys/bus/usb/devices/?-?/') - for i in usb_devices: - retcode, output = kobo.shortcuts.run('echo 2 > %spower/autosuspend' % i) - retcode, output = kobo.shortcuts.run('echo auto > %spower/level' % i) \ No newline at end of file +# usb_devices = glob.glob('/sys/bus/usb/devices/?-?/') +# for i in usb_devices: +# retcode, output = kobo.shortcuts.run('echo 2 > %spower/autosuspend' % i) +# retcode, output = kobo.shortcuts.run('echo auto > %spower/level' % i) \ No newline at end of file diff --git a/commands/cmd_laptop_mode.py b/commands/cmd_laptop_mode.py deleted file mode 100644 index a28517f..0000000 --- a/commands/cmd_laptop_mode.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- - - -from kobo.cli import Command -import os - -class Laptop(Command): - """laptop mode not implemented yet""" - 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): - # this should be part of ktune - # if on wifi then switch off network card? - # usb suspend set to auto - pass diff --git a/commands/cmd_list.py b/commands/cmd_list.py new file mode 100644 index 0000000..e939dff --- /dev/null +++ b/commands/cmd_list.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +import os +import os.path +import glob +import kobo.shortcuts +from kobo.cli import Command + +class List(Command): + """list of modes""" + 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_modes.py b/commands/cmd_modes.py new file mode 100644 index 0000000..0c967e0 --- /dev/null +++ b/commands/cmd_modes.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +import os +import os.path +import glob +import kobo.shortcuts +from kobo.cli import Command + +class Modes(Command): + """set mode""" + 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 modes > 0: + print 'Mode %s' % args[0] + file1 = ('/etc/tune-profiles/%s/ktune.conf' % args[0]) + os.symlink(file1, '/etc/ktune.d/ktune.conf') + file2 = ('/etc/tune-profiles/%s/ktune.sh' % args[0]) + os.symlink(file2, '/etc/ktune.d/ktune.sh') + os.rename('/etc/tuned.conf', '/etc/tuned.conf.bckp') + file3 = ('/etc/tune-profiles/%s/tuned.conf' % args[0]) + os.symlink(file3, '/etc/tuned.conf') + #if os.path.exists("/etc/tune-profiles/server/ktune"): + os.rename('/etc/sysconfig/ktune', '/etc/sysconfig/ktune.bckp') + file4 = ('/etc/tune-profiles/%s/ktune' % args[0]) + os.symlink(file4, '/etc/sysconfig/ktune') + + os.system('service ktune start') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') + + os.system('service tuned start --config=/etc/tune-profiles/server/tuned.conf') + os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') \ No newline at end of file diff --git a/commands/cmd_off_mode.py b/commands/cmd_off_mode.py index fcb16a8..d9b8e5f 100644 --- a/commands/cmd_off_mode.py +++ b/commands/cmd_off_mode.py @@ -21,16 +21,17 @@ class Off(Command): def run(self, *args, **kwargs): - os.system("rm -rf /etc/ktune.d/{server,laptop}.conf") - os.system("rm -rf /etc/ktune.d/{server,laptop}.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("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') usb_devices = glob.glob('/sys/bus/usb/devices/?-?/') + # test whether usb suspend is on for i in usb_devices: - retcode, output = kobo.shortcuts.run('echo on > %spower/level' % i) + retcode, output = kobo.shortcuts.run('echo on > %spower/level' % i) diff --git a/commands/cmd_personal_mode.py b/commands/cmd_personal_mode.py deleted file mode 100644 index f65c721..0000000 --- a/commands/cmd_personal_mode.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- - - -import os -import sys -import kobo.shortcuts -from kobo.cli import Command - - -class Personal(Command): - """set personal mode""" - 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): - # call script with personal setting from /etc/ktune.d/ - if len(args) != 1: - self.parser.error("Argument missing.") - - name_p = args[0] - show_disabled = kwargs.pop("show_disabled") - - try: - # for include two strings into function: % (foo, foo) - #retcode, output = kobo.shortcuts.run('/etc/ktune.d/%s.sh' % name_p) - pass - except RuntimeError, ex: - print str(ex) - sys.exit(1) - diff --git a/commands/cmd_server_mode.py b/commands/cmd_server_mode.py deleted file mode 100644 index 7a496ae..0000000 --- a/commands/cmd_server_mode.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -import os.path -import glob -import kobo.shortcuts -from kobo.cli import Command - -class Server(Command): - """set server mode""" - 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/server/server.conf"): - os.symlink("/etc/tune-profiles/server/server.conf", "/etc/ktune.d/server.conf") - if os.path.exists("/etc/tune-profiles/server/server.sh"): - os.symlink("/etc/tune-profiles/server/server.sh", "/etc/ktune.d/server.sh") - if os.path.exists("/etc/tune-profiles/server/ktune"): - os.system('mv /etc/sysconfig/ktune /etc/sysconfig/ktune.bckp') - os.symlink("/etc/tune-profiles/server/ktune", "/etc/sysconfig/ktune") - if os.path.exists("/etc/tune-profiles/server/tuned.conf"): - os.system("mv /etc/tuned.conf /etc/tuned.conf.bckp") - os.symlink("/etc/tune-profiles/server/tuned.conf", "/etc/tuned.conf") - os.system('service ktune start') - os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') - - os.system('service tuned start --config=/etc/tune-profiles/server/tuned.conf') - os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') - - # check all usb-devices in format digit-digit f.e. 1-1 - usb_devices = glob.glob('/sys/bus/usb/devices/?-?/') - # all usb devices set to auto with 2s idle - for i in usb_devices: - retcode, output = kobo.shortcuts.run('echo 2 > %spower/autosuspend' % i) - retcode, output = kobo.shortcuts.run('echo auto > %spower/level' % i)