summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Knirsch <pknirsch@hamburg.stuttgart.redhat.com>2009-02-25 11:45:48 +0100
committerPhilip Knirsch <pknirsch@hamburg.stuttgart.redhat.com>2009-02-25 11:45:48 +0100
commitca552606191920c1f6d02c28b80273d2e9d4349a (patch)
tree33d7eda5f5b7ffe1d842a2c9395ea2a03650d01a
parent1fa57228447abc46d58bcc377ab373c026ccd008 (diff)
downloadtuned-ca552606191920c1f6d02c28b80273d2e9d4349a.zip
tuned-ca552606191920c1f6d02c28b80273d2e9d4349a.tar.gz
tuned-ca552606191920c1f6d02c28b80273d2e9d4349a.tar.xz
- Added complete cleanup code in case of tuned exiting and/or
getting a SIGTERM to restore default values - Made the disk tuning pluging less nosy if started as non-daemon - Fixed missing self. in the tuned.py config handling
-rw-r--r--monitorplugins/disk.py3
-rw-r--r--monitorplugins/net.py3
-rwxr-xr-xtuned8
-rw-r--r--tuned.py12
-rw-r--r--tuningplugins/disk.py8
-rw-r--r--tuningplugins/net.py4
6 files changed, 31 insertions, 7 deletions
diff --git a/monitorplugins/disk.py b/monitorplugins/disk.py
index 16262ab..a66f4b6 100644
--- a/monitorplugins/disk.py
+++ b/monitorplugins/disk.py
@@ -60,6 +60,9 @@ class DiskMonitor:
def init(self, config):
self.config = config
+ def cleanup(self):
+ pass
+
def getLoad(self):
self.__update__()
ret = {}
diff --git a/monitorplugins/net.py b/monitorplugins/net.py
index caf8307..114f1f0 100644
--- a/monitorplugins/net.py
+++ b/monitorplugins/net.py
@@ -69,6 +69,9 @@ class NetMonitor:
for d in self.devices.keys():
self.devices[d]["max"] = [70*1024*1024*interval, 1, 70*1024*1024*interval, 1]
+ def cleanup(self):
+ pass
+
def getLoad(self):
self.__update__()
ret = {}
diff --git a/tuned b/tuned
index 126200c..8452947 100755
--- a/tuned
+++ b/tuned
@@ -20,11 +20,14 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
-import sys, os.path, getopt
+import sys, os.path, getopt, atexit, signal
def usage():
print "Usage: tuned [-d|--daemon] [-c conffile|--config=conffile]"
+def handler(signum, frame):
+ sys.exit()
+
def daemonize():
try:
pid = os.fork()
@@ -76,6 +79,9 @@ if __name__ == "__main__":
from tuned import tuned
+ atexit.register(tuned.cleanup)
+ signal.signal(signal.SIGTERM, handler)
+
tuned.init(TUNEDDIR, cfgfile)
tuned.run()
tuned.cleanup()
diff --git a/tuned.py b/tuned.py
index 9d56f85..b41c2dc 100644
--- a/tuned.py
+++ b/tuned.py
@@ -22,10 +22,10 @@ class Tuned:
def init(self, path, cfgfile):
self.config = ConfigParser.ConfigParser()
self.config.read(cfgfile)
- if config.has_option("main", "interval"):
- self.interval = config.getint("main", "interval")
+ if self.config.has_option("main", "interval"):
+ self.interval = self.config.getint("main", "interval")
else:
- config.set("main", "interval", self.interval)
+ self.config.set("main", "interval", self.interval)
self.__initplugins__(path, "monitorplugins", self.mp)
self.__initplugins__(path, "tuningplugins", self.tp)
for p in self.mp:
@@ -43,7 +43,11 @@ class Tuned:
p.setTuning(lh)
time.sleep(self.interval)
- def cleanup(self):
+ def cleanup(self, signum=0, frame=None):
print("Cleanup...")
+ for p in self.mp:
+ p.cleanup()
+ for p in self.tp:
+ p.cleanup()
tuned = Tuned()
diff --git a/tuningplugins/disk.py b/tuningplugins/disk.py
index 6624890..3f0067e 100644
--- a/tuningplugins/disk.py
+++ b/tuningplugins/disk.py
@@ -36,6 +36,10 @@ class DiskTuning:
def init(self, config):
self.config = config
+ def cleanup(self):
+ for dev in self.devidle.keys():
+ os.system("hdparm -S0 -B255 /dev/"+dev+" > /dev/null 2>&1")
+
def setTuning(self, load):
disks = load.setdefault("DISK", {})
for dev in disks.keys():
@@ -43,10 +47,10 @@ class DiskTuning:
self.__updateIdle__(dev, devload)
if self.devidle[dev]["LEVEL"] == 0 and self.devidle[dev]["READ"] >= 30 and self.devidle[dev]["WRITE"] >= 30:
self.devidle[dev]["LEVEL"] = 1
- os.system("hdparm -Y -S60 -B1 /dev/"+dev)
+ os.system("hdparm -Y -S60 -B1 /dev/"+dev+" > /dev/null 2>&1")
if self.devidle[dev]["LEVEL"] > 0 and (self.devidle[dev]["READ"] == 0 or self.devidle[dev]["WRITE"] == 0):
self.devidle[dev]["LEVEL"] = 0
- os.system("hdparm -S255 -B127 /dev/"+dev)
+ os.system("hdparm -S255 -B127 /dev/"+dev+" > /dev/null 2>&1")
print(load, self.devidle)
_plugin = DiskTuning()
diff --git a/tuningplugins/net.py b/tuningplugins/net.py
index 687d306..4529253 100644
--- a/tuningplugins/net.py
+++ b/tuningplugins/net.py
@@ -36,6 +36,10 @@ class NetTuning:
def init(self, config):
self.config = config
+ def cleanup(self):
+ for dev in self.devidle.keys():
+ os.system("ethtool -s "+dev+" advertise 0x03F")
+
def setTuning(self, load):
disks = load.setdefault("NET", {})
for dev in disks.keys():