/[svn.andrew.net.au]/usbspindownd/usbspindownd.py
ViewVC logotype

Diff of /usbspindownd/usbspindownd.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 32 by apollock, Thu Jan 31 04:45:24 2008 UTC revision 33 by apollock, Thu Jan 31 07:58:04 2008 UTC
# Line 28  import ConfigParser Line 28  import ConfigParser
28  import sys  import sys
29  import os  import os
30  import time  import time
31    import signal
32    
33  spindown_cmd = ""  spindown_cmd = ""
34  spindown_cmd_args = ""  spindown_cmd_args = ""
35    keep_running = True
36    signals = {}
37    
38    def signal_handler(signal, stack):
39      global keep_running
40      global sigdict
41      keep_running = False
42    
43    
44    def getsignals():
45      signals = {}
46      for name in dir(signal):
47        if name.startswith("SIG"):
48          signals[getattr(signal, name)] = name
49      return signals
50    
 #  
 # Disk, how long to wait for, last msio value, spun down  
 #  
51    
52  def search_path(filename, search_path):  def search_path(filename, search_path):
53    file_found = False    file_found = False
# Line 53  def debug(options, message): Line 66  def debug(options, message):
66    if options.debug:    if options.debug:
67      print "%s: %s" % (time.asctime(time.localtime()), message)      print "%s: %s" % (time.asctime(time.localtime()), message)
68    
69    
70    def log(message):
71      pass
72    
73    
74  def load_config(options):  def load_config(options):
75    global spindown_cmd, spindown_cmd_args    global spindown_cmd, spindown_cmd_args
76    cf = ConfigParser.SafeConfigParser()    cf = ConfigParser.SafeConfigParser()
# Line 108  def spin_down(options, disk): Line 126  def spin_down(options, disk):
126    
127    
128  def monitor_disks(config, options):  def monitor_disks(config, options):
129      global keep_running
130    debug(options, "Monitoring disks")    debug(options, "Monitoring disks")
131    while True:    while keep_running:
132      for disk in config:      for disk in config:
133        debug(options, "Considering %s" % (disk))        debug(options, "Considering %s" % (disk))
134        ds = diskstats.DiskStats(disk)        ds = diskstats.DiskStats(disk)
# Line 142  def monitor_disks(config, options): Line 161  def monitor_disks(config, options):
161            else:            else:
162              # This disk is ineligible for spinning down at this time              # This disk is ineligible for spinning down at this time
163              debug(options, "Disk idle for %s seconds, but not for long enough (%s)" % (now - config[disk]["timestamp"], config[disk]["wait"]))              debug(options, "Disk idle for %s seconds, but not for long enough (%s)" % (now - config[disk]["timestamp"], config[disk]["wait"]))
             #config[disk]["timestamp"] = int(time.time())  
164          else:          else:
165            debug(options, "Disk not idle (old msio: %s, current msio: %s)" % (config[disk]["last_msio"], msio))            debug(options, "Disk not idle (old msio: %s, current msio: %s)" % (config[disk]["last_msio"], msio))
166            config[disk]["last_msio"] = msio            config[disk]["last_msio"] = msio
# Line 150  def monitor_disks(config, options): Line 168  def monitor_disks(config, options):
168            config[disk]["spun_down"] = False            config[disk]["spun_down"] = False
169      debug(options, "Sleeping")      debug(options, "Sleeping")
170      time.sleep(60)      time.sleep(60)
171      debug(options, "Shutting down")
172    
173  def main():  def main():
174      global options
175      global signals
176      signals = getsignals()
177      signal.signal(signal.SIGTERM, signal_handler)
178      signal.signal(signal.SIGINT, signal_handler)
179    parser = optparse.OptionParser()    parser = optparse.OptionParser()
180    parser.add_option("-n", "--dry-run",    parser.add_option("-n", "--dry-run",
181      action="store_true",      action="store_true",

Legend:
Removed from v.32  
changed lines
  Added in v.33

  ViewVC Help
Powered by ViewVC 1.1.22