From b7a092f3e7b598ee771ecbe881fe0c9db9e350a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcela=20Ma=C5=A1l=C3=A1=C5=88ov=C3=A1?= Date: Thu, 9 Jul 2009 13:23:10 +0200 Subject: [PATCH 1/4] Initial commit of commandline tool. --- README.command | 8 +++++++ commands/__init__.py | 0 commands/cmd_default_mode.py | 25 ++++++++++++++++++++ commands/cmd_laptop_mode.py | 26 +++++++++++++++++++++ commands/cmd_server_mode.py | 26 +++++++++++++++++++++ man/tuned_adm.1 | 45 ++++++++++++++++++++++++++++++++++++ tuned_adm.py | 22 ++++++++++++++++++ 7 files changed, 152 insertions(+) create mode 100644 README.command create mode 100644 commands/__init__.py create mode 100644 commands/cmd_default_mode.py create mode 100644 commands/cmd_laptop_mode.py create mode 100644 commands/cmd_server_mode.py create mode 100644 man/tuned_adm.1 create mode 100755 tuned_adm.py diff --git a/README.command b/README.command new file mode 100644 index 0000000..424cd22 --- /dev/null +++ b/README.command @@ -0,0 +1,8 @@ +tuned_adm.py +------------ +tuned_adm.py is commandline tool for setting modes +which needs ktune and kobo packages. kobo is in repo, +ktune must be rebuilt from srpm. + +Commandline is calling ktune with 'tuned_adm.py server' +and setting it back by call 'tuned_adm.py default'. diff --git a/commands/__init__.py b/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/commands/cmd_default_mode.py b/commands/cmd_default_mode.py new file mode 100644 index 0000000..ddc928e --- /dev/null +++ b/commands/cmd_default_mode.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + + +from kobo.cli import Command +import os + +class Default(Command): + """set default 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): + os.system('service ktune stop') + os.system('service tuned stop') + diff --git a/commands/cmd_laptop_mode.py b/commands/cmd_laptop_mode.py new file mode 100644 index 0000000..6f59664 --- /dev/null +++ b/commands/cmd_laptop_mode.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + + +from kobo.cli import Command +import os + +class Laptop(Command): + """set laptop 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): + # this should be part of ktune + # if on wifi then switch off network card? + pass diff --git a/commands/cmd_server_mode.py b/commands/cmd_server_mode.py new file mode 100644 index 0000000..6b89c53 --- /dev/null +++ b/commands/cmd_server_mode.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + + +from kobo.cli import Command +import os + +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): + # call ktune - need check of status + os.system('service ktune start') + # usb suspend? + diff --git a/man/tuned_adm.1 b/man/tuned_adm.1 new file mode 100644 index 0000000..8b41a8e --- /dev/null +++ b/man/tuned_adm.1 @@ -0,0 +1,45 @@ +.\"/* +.\" * All rights reserved +.\" * Copyright (C) 2009 Red Hat, Inc. +.\" * Authors: Marcela Mašláňová +.\" * +.\" * 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. +.\" */ +.\" +.TH TUNED_ADM "1" "9 Jul 2009" "Linux Programmer's Manual" +.SH NAME +tuned_adm \- commandline tool for setting the power-save options +.SH SYNOPSIS +.B tuned_adm +.B +.BR help ", " laptop ", " server +.br +.SH DESCRIPTION +This command line utility allows user to set profile for server or laptop. +.SH "OPTIONS" +.TP +.B help +Print out the list of commands. +.TP +.B laptop +.TP +.B server +.TP +These settings are calling ktune which set up different values for better resource consumption. + +.SH "SEE ALSO" +.SH AUTHOR +.nf +Marcela Mašláňová diff --git a/tuned_adm.py b/tuned_adm.py new file mode 100755 index 0000000..a9e0c8b --- /dev/null +++ b/tuned_adm.py @@ -0,0 +1,22 @@ +#!/usr/bin/python + +import os +import sys +import locale +from kobo.cli import * + + +from kobo.tback import * +set_except_hook() + + +import commands +CommandContainer.register_module(commands) + + +def main(argv): + parser = CommandOptionParser(command_container=CommandContainer(), default_command="help") + parser.run() + +if __name__ == "__main__": + main(sys.argv[1:]) From 9490bc08b339e4b07601f60d10ce8e3c79d18a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcela=20Ma=C5=A1l=C3=A1=C5=88ov=C3=A1?= Date: Mon, 27 Jul 2009 16:36:24 +0200 Subject: [PATCH 2/4] Specified commands for tuned-adm (default, server, off). Start to use gitignore. --- .gitignore | 3 +++ Makefile | 19 +++++++++++---- README.command | 4 ++-- commands/cmd_default_mode.py | 17 ++++++++++---- commands/cmd_laptop_mode.py | 3 ++- commands/cmd_off_mode.py | 37 +++++++++++++++++++++++++++++ commands/cmd_personal_mode.py | 40 ++++++++++++++++++++++++++++++++ commands/cmd_server_mode.py | 26 +++++++++++++++++---- man/{tuned_adm.1 => tuned-adm.1} | 18 ++++++++++---- tuned_adm.py => tuned-adm | 4 ++++ tuned.spec | 14 +++++++++-- 11 files changed, 162 insertions(+), 23 deletions(-) create mode 100644 .gitignore create mode 100644 commands/cmd_off_mode.py create mode 100644 commands/cmd_personal_mode.py rename man/{tuned_adm.1 => tuned-adm.1} (77%) rename tuned_adm.py => tuned-adm (80%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f18e674 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +latest-archive +*tar.bz2 diff --git a/Makefile b/Makefile index 3e229c9..78e8a9a 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,13 @@ DESTDIR = / MANDIR = /usr/share/man/ GITTAG = v$(VERSION) -DIRS = doc contrib tuningplugins monitorplugins -FILES = tuned tuned.spec Makefile tuned.py tuned.initscript tuned.conf +DIRS = doc contrib tuningplugins monitorplugins commands +FILES = tuned tuned.spec Makefile tuned.py tuned.initscript tuned.conf tuned-adm FILES_doc = doc/DESIGN.txt doc/README.utils doc/TIPS.txt doc/tuned.8 doc/tuned.conf.5 doc/README.scomes -FILES_contrib = contrib/diskdevstat contrib/netdevstat contrib/scomes -FILES_tuningplugins = tuningplugins/disk.py tuningplugins/net.py tuningplugins/__init__.py -FILES_monitorplugins = monitorplugins/disk.py monitorplugins/net.py monitorplugins/__init__.py +FILES_contrib = contrib/diskdevstat contrib/netdevstat contrib/scomes contrib/varnetload +FILES_tuningplugins = tuningplugins/cpu.py tuningplugins/disk.py tuningplugins/net.py tuningplugins/__init__.py +FILES_monitorplugins = monitorplugins/cpu.py 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 DOCS = AUTHORS ChangeLog COPYING INSTALL NEWS README distarchive: tag archive @@ -29,6 +30,7 @@ archive: cp $(FILES_contrib) $(VERSIONED_NAME)/contrib cp $(FILES_tuningplugins) $(VERSIONED_NAME)/tuningplugins cp $(FILES_monitorplugins) $(VERSIONED_NAME)/monitorplugins + cp $(FILES_commands) $(VERSIONED_NAME)/commands tar cjf $(VERSIONED_NAME).tar.bz2 $(VERSIONED_NAME) ln -fs $(VERSIONED_NAME).tar.bz2 latest-archive @@ -52,11 +54,13 @@ install: # Install the binaries mkdir -p $(DESTDIR)/usr/sbin/ install -m 0755 tuned $(DESTDIR)/usr/sbin/ + install -m 0755 tuned-adm $(DESTDIR)/usr/sbin/ # Install the plugins and classes mkdir -p $(DESTDIR)/usr/share/$(NAME)/ mkdir -p $(DESTDIR)/usr/share/$(NAME)/tuningplugins mkdir -p $(DESTDIR)/usr/share/$(NAME)/monitorplugins + mkdir -p $(DESTDIR)/usr/share/$(NAME)/commands install -m 0644 tuned.py $(DESTDIR)/usr/share/$(NAME)/ for file in $(FILES_tuningplugins); do \ install -m 0644 $$file $(DESTDIR)/usr/share/$(NAME)/tuningplugins; \ @@ -64,6 +68,9 @@ install: for file in $(FILES_monitorplugins); do \ install -m 0644 $$file $(DESTDIR)/usr/share/$(NAME)/monitorplugins; \ done + for file in $(FILES_commands); do \ + install -m 0644 $$file $(DESTDIR)/usr/share/$(NAME)/commands; \ + done # Install contrib systemtap scripts for file in $(FILES_contrib); do \ @@ -74,6 +81,8 @@ install: mkdir -p $(DESTDIR)/etc install -m 0644 tuned.conf $(DESTDIR)/etc + mkdir -p $(DESTDIR)/etc/tune-profiles/{desktop,laptop,personal,server} + # Install initscript mkdir -p $(DESTDIR)/etc/rc.d/init.d install -m 0755 tuned.initscript $(DESTDIR)/etc/rc.d/init.d/tuned diff --git a/README.command b/README.command index 424cd22..9d7dc86 100644 --- a/README.command +++ b/README.command @@ -4,5 +4,5 @@ tuned_adm.py is commandline tool for setting modes which needs ktune and kobo packages. kobo is in repo, ktune must be rebuilt from srpm. -Commandline is calling ktune with 'tuned_adm.py server' -and setting it back by call 'tuned_adm.py default'. +Commandline is calling ktune with 'tuned-adm default' +and setting it back by call 'tuned-adm off'. diff --git a/commands/cmd_default_mode.py b/commands/cmd_default_mode.py index ddc928e..8bc270f 100644 --- a/commands/cmd_default_mode.py +++ b/commands/cmd_default_mode.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- - -from kobo.cli import Command import os +import glob +import kobo.shortcuts +from kobo.cli import Command class Default(Command): - """set default mode""" + """star ktune and tuned with default settings""" enabled = True def options(self): @@ -20,6 +21,12 @@ class Default(Command): def run(self, *args, **kwargs): - os.system('service ktune stop') - os.system('service tuned stop') + os.system('service ktune start') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') + 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 diff --git a/commands/cmd_laptop_mode.py b/commands/cmd_laptop_mode.py index 6f59664..a28517f 100644 --- a/commands/cmd_laptop_mode.py +++ b/commands/cmd_laptop_mode.py @@ -5,7 +5,7 @@ from kobo.cli import Command import os class Laptop(Command): - """set laptop mode""" + """laptop mode not implemented yet""" enabled = True @@ -23,4 +23,5 @@ class Laptop(Command): 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_off_mode.py b/commands/cmd_off_mode.py new file mode 100644 index 0000000..d335752 --- /dev/null +++ b/commands/cmd_off_mode.py @@ -0,0 +1,37 @@ +# -*- 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): + if os.path.exists("/etc/tune.d/*.conf"): + os.remove("/etc/tune.d/*.conf") + if os.path.exists("/etc/tune.d/*.sh"): + os.remove("/etc/tune.d/*.sh") + if os.path.exists("/etc/sysconfig/ktune.bckp"): + os.system('mv /etc/sysconfig/ktune.bckp /etc/sysconfig/ktune') + os.remove("/etc/sysconfig/ktune") + 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/?-?/') + for i in usb_devices: + retcode, output = kobo.shortcuts.run('echo on > %spower/level' % i) diff --git a/commands/cmd_personal_mode.py b/commands/cmd_personal_mode.py new file mode 100644 index 0000000..f65c721 --- /dev/null +++ b/commands/cmd_personal_mode.py @@ -0,0 +1,40 @@ +# -*- 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 index 6b89c53..4d250a7 100644 --- a/commands/cmd_server_mode.py +++ b/commands/cmd_server_mode.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- - -from kobo.cli import Command import os +import os.path +import glob +import kobo.shortcuts +from kobo.cli import Command class Server(Command): """set server mode""" @@ -20,7 +22,23 @@ class Server(Command): def run(self, *args, **kwargs): - # call ktune - need check of status + # 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/tune.d/server.conf") + if os.path.exists("/etc/tune-profiles/server/server.sh"): + os.symlink("/etc/tune-profiles/server/server.sh", "/etc/tune.d/server.sh") + os.system('mv /etc/sysconfig/ktune /etc/sysconfig/ktune.bckp') + if os.path.exists("/etc/tune-profiles/server/ktune"): + os.symlink("/etc/tune-profiles/server/ktune", "/etc/sysconfig/ktune") os.system('service ktune start') - # usb suspend? + 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) diff --git a/man/tuned_adm.1 b/man/tuned-adm.1 similarity index 77% rename from man/tuned_adm.1 rename to man/tuned-adm.1 index 8b41a8e..2540021 100644 --- a/man/tuned_adm.1 +++ b/man/tuned-adm.1 @@ -20,26 +20,36 @@ .\" .TH TUNED_ADM "1" "9 Jul 2009" "Linux Programmer's Manual" .SH NAME -tuned_adm \- commandline tool for setting the power-save options +tuned-adm \- commandline tool for setting the power-save options .SH SYNOPSIS -.B tuned_adm +.B tuned-adm .B -.BR help ", " laptop ", " server +.BR help ", " laptop ", " server ", " default ", " off " .br .SH DESCRIPTION This command line utility allows user to set profile for server or laptop. .SH "OPTIONS" + +.SS .TP .B help Print out the list of commands. + .TP .B laptop + .TP .B server -.TP These settings are calling ktune which set up different values for better resource consumption. +It also switch on tuned daemon and add ktune and tuned into chkconfig. Usbsuspend is set. + +.TP +.B off +Switch off all ktune and tuned settings and remove them from services. The configuration file are +set to previous settings. .SH "SEE ALSO" +.BR tuned (8) .SH AUTHOR .nf Marcela Mašláňová diff --git a/tuned_adm.py b/tuned-adm similarity index 80% rename from tuned_adm.py rename to tuned-adm index a9e0c8b..7a4b511 100755 --- a/tuned_adm.py +++ b/tuned-adm @@ -10,6 +10,10 @@ 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) diff --git a/tuned.spec b/tuned.spec index f910bd0..71373db 100644 --- a/tuned.spec +++ b/tuned.spec @@ -1,7 +1,7 @@ Summary: A dynamic adaptive system tuning daemon Name: tuned -Version: 0.1.6 -Release: 1%{?dist} +Version: 0.1.7 +Release: 2%{?dist}test License: GPLv2+ Group: System Environment/Daemons # The source for this package was pulled from upstream git. Use the @@ -18,6 +18,7 @@ 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. @@ -70,6 +71,8 @@ fi %{_initddir}/tuned %config(noreplace) %{_sysconfdir}/tuned.conf %{_sbindir}/tuned +%{_sbindir}/tuned-adm +%{_sysconfdir}/tune-profiles %{_datadir}/tuned %{_mandir}/man5/* %{_mandir}/man8/* @@ -78,12 +81,19 @@ fi %defattr(-,root,root,-) %doc doc/README.utils %doc doc/README.scomes +%{_sbindir}/varnetload %{_sbindir}/netdevstat %{_sbindir}/diskdevstat %{_sbindir}/scomes %changelog +* Mon Jul 27 2009 Marcela Mašláňová - 0.1.7-2 +- tuned-adm - CLI for setting profiles + +* Thu Jul 16 2009 Phil Knirsch - 0.1.7-1 +- Added first version CPU tuning and monitoring plugins + * Thu Jun 25 2009 Petr Lautrbach - 0.1.6-1 - added scomes From 27a8af70efd6f78838ec2f9ded11062fe6d287d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcela=20Ma=C5=A1l=C3=A1=C5=88ov=C3=A1?= Date: Tue, 28 Jul 2009 13:10:55 +0200 Subject: [PATCH 3/4] Fix commands server and off. --- Makefile | 4 ++-- commands/cmd_off_mode.py | 11 +++++------ commands/cmd_server_mode.py | 9 ++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 78e8a9a..af359f1 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ DIRS = doc contrib tuningplugins monitorplugins commands FILES = tuned tuned.spec Makefile tuned.py tuned.initscript tuned.conf tuned-adm FILES_doc = doc/DESIGN.txt doc/README.utils doc/TIPS.txt doc/tuned.8 doc/tuned.conf.5 doc/README.scomes FILES_contrib = contrib/diskdevstat contrib/netdevstat contrib/scomes contrib/varnetload -FILES_tuningplugins = tuningplugins/cpu.py tuningplugins/disk.py tuningplugins/net.py tuningplugins/__init__.py -FILES_monitorplugins = monitorplugins/cpu.py monitorplugins/disk.py monitorplugins/net.py monitorplugins/__init__.py +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 DOCS = AUTHORS ChangeLog COPYING INSTALL NEWS README diff --git a/commands/cmd_off_mode.py b/commands/cmd_off_mode.py index d335752..fcb16a8 100644 --- a/commands/cmd_off_mode.py +++ b/commands/cmd_off_mode.py @@ -21,13 +21,12 @@ class Off(Command): def run(self, *args, **kwargs): - if os.path.exists("/etc/tune.d/*.conf"): - os.remove("/etc/tune.d/*.conf") - if os.path.exists("/etc/tune.d/*.sh"): - os.remove("/etc/tune.d/*.sh") + 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.system('mv /etc/sysconfig/ktune.bckp /etc/sysconfig/ktune') - os.remove("/etc/sysconfig/ktune") + 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') diff --git a/commands/cmd_server_mode.py b/commands/cmd_server_mode.py index 4d250a7..7a496ae 100644 --- a/commands/cmd_server_mode.py +++ b/commands/cmd_server_mode.py @@ -24,12 +24,15 @@ class Server(Command): 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/tune.d/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/tune.d/server.sh") - os.system('mv /etc/sysconfig/ktune /etc/sysconfig/ktune.bckp') + 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') From 9d168d837db6d165730f72e6b29f0d2e610a8983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcela=20Ma=C5=A1l=C3=A1=C5=88ov=C3=A1?= Date: Thu, 30 Jul 2009 16:30:52 +0200 Subject: [PATCH 4/4] Rewrite commands only to: default, help, list, modes, off. The different modes could be specified in /etc/tune-profiles and then can be listed by list: tuned-adm list and set by: tuned-adm modes YourFavourite --- Makefile | 5 ++-- commands/cmd_default_mode.py | 8 +++--- commands/cmd_laptop_mode.py | 27 -------------------- commands/cmd_list.py | 33 ++++++++++++++++++++++++ commands/cmd_modes.py | 46 ++++++++++++++++++++++++++++++++++ commands/cmd_off_mode.py | 15 +++++------ commands/cmd_personal_mode.py | 40 ----------------------------- commands/cmd_server_mode.py | 47 ----------------------------------- 8 files changed, 94 insertions(+), 127 deletions(-) delete mode 100644 commands/cmd_laptop_mode.py create mode 100644 commands/cmd_list.py create mode 100644 commands/cmd_modes.py delete mode 100644 commands/cmd_personal_mode.py delete mode 100644 commands/cmd_server_mode.py 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)