clearer names for actions, and infer actions better
[monitor.git] / commands / reboot.py
1 #!/usr/bin/python
2
3 from monitor.reboot import *
4 import time
5
6 def main():
7         logger.setLevel(logging.DEBUG)
8         ch = logging.StreamHandler()
9         ch.setLevel(logging.DEBUG)
10         formatter = logging.Formatter('LOGGER - %(message)s')
11         ch.setFormatter(formatter)
12         logger.addHandler(ch)
13
14         try:
15                 if "test" in sys.argv:
16                         dryrun = True
17                 else:
18                         dryrun = False
19
20                 for node in sys.argv[1:]:
21                         if node == "test": continue
22
23                         print "Rebooting %s" % node
24                         if reboot_policy(node, True, dryrun):
25                                 print "success"
26                         else:
27                                 print "failed"
28         except Exception, err:
29                 import traceback; traceback.print_exc()
30                 from monitor.common import email_exception
31                 email_exception(node)
32                 print err
33
34 if __name__ == '__main__':
35         main()
36         f = open("/tmp/rebootlog", 'a')
37         f.write("reboot %s %s\n" % (time.time(), " ".join(sys.argv[1:])))
38         f.close()