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 111d228..377623c 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ FILES_contrib = contrib/diskdevstat contrib/netdevstat contrib/scomes contrib/va 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_ktune = ktune/ktune.init ktune/ktune.sysconfig ktune/sysctl.ktune ktune/README.ktune +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 @@ -31,6 +33,7 @@ archive: cp $(FILES_tuningplugins) $(VERSIONED_NAME)/tuningplugins cp $(FILES_monitorplugins) $(VERSIONED_NAME)/monitorplugins cp $(FILES_ktune) $(VERSIONED_NAME)/ktune + cp $(FILES_commands) $(VERSIONED_NAME)/commands tar cjf $(VERSIONED_NAME).tar.bz2 $(VERSIONED_NAME) ln -fs $(VERSIONED_NAME).tar.bz2 latest-archive @@ -54,11 +57,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; \ @@ -66,6 +71,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 \ @@ -76,6 +84,8 @@ install: mkdir -p $(DESTDIR)/etc install -m 0644 tuned.conf $(DESTDIR)/etc + mkdir -p $(DESTDIR)/etc/tune-profiles/ + # 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 new file mode 100644 index 0000000..9d7dc86 --- /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 default' +and setting it back by call 'tuned-adm off'. 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..539a451 --- /dev/null +++ b/commands/cmd_default_mode.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +import os +import glob +import kobo.shortcuts +from kobo.cli import Command + +class Default(Command): + """star ktune and tuned with default settings""" + 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 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_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 new file mode 100644 index 0000000..d9b8e5f --- /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): + 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) diff --git a/man/tuned-adm.1 b/man/tuned-adm.1 new file mode 100644 index 0000000..2540021 --- /dev/null +++ b/man/tuned-adm.1 @@ -0,0 +1,55 @@ +.\"/* +.\" * 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 ", " 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 +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 b/tuned-adm new file mode 100755 index 0000000..7a4b511 --- /dev/null +++ b/tuned-adm @@ -0,0 +1,26 @@ +#!/usr/bin/python + +import os +import sys +import locale +from kobo.cli import * + + +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() + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/tuned.spec b/tuned.spec index 49b66a6..0cedf64 100644 --- a/tuned.spec +++ b/tuned.spec @@ -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. @@ -74,6 +75,8 @@ fi %{_initddir}/tuned %config(noreplace) %{_sysconfdir}/tuned.conf %{_sbindir}/tuned +%{_sbindir}/tuned-adm +%{_sysconfdir}/tune-profiles %{_datadir}/tuned %{_mandir}/man5/* %{_mandir}/man8/*