1
0
Fork 0

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
This commit is contained in:
Marcela Mašláňová 2009-07-30 16:30:52 +02:00
parent 27a8af70ef
commit 9d168d837d
8 changed files with 94 additions and 127 deletions

View file

@ -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

View file

@ -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)
# 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)

View file

@ -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

33
commands/cmd_list.py Normal file
View file

@ -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."

46
commands/cmd_modes.py Normal file
View file

@ -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')

View file

@ -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)

View file

@ -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)

View file

@ -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)