summaryrefslogtreecommitdiffstats
path: root/testing/mozharness/external_tools/count_and_reboot.py
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozharness/external_tools/count_and_reboot.py
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozharness/external_tools/count_and_reboot.py')
-rwxr-xr-xtesting/mozharness/external_tools/count_and_reboot.py62
1 files changed, 62 insertions, 0 deletions
diff --git a/testing/mozharness/external_tools/count_and_reboot.py b/testing/mozharness/external_tools/count_and_reboot.py
new file mode 100755
index 000000000..9e8ae35a6
--- /dev/null
+++ b/testing/mozharness/external_tools/count_and_reboot.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+# encoding: utf-8
+# Created by Chris AtLee on 2008-11-04
+"""count_and_reboot.py [-n maxcount] -f countfile
+
+Increments the value in countfile, and reboots the machine once the count
+reaches or exceeds maxcount."""
+
+import os, sys, time
+
+if sys.platform in ('darwin', 'linux2'):
+ def reboot():
+ # -S means to accept password from stdin, which we then redirect from
+ # /dev/null
+ # This results in sudo not waiting forever for a password. If sudoers
+ # isn't set up properly, this will fail immediately
+ os.system("sudo -S reboot < /dev/null")
+ # After starting the shutdown, we go to sleep since the system can
+ # take a few minutes to shut everything down and reboot
+ time.sleep(600)
+
+elif sys.platform == "win32":
+ # Windows
+ def reboot():
+ os.system("shutdown -f -r -t 0")
+ # After starting the shutdown, we go to sleep since the system can
+ # take a few minutes to shut everything down and reboot
+ time.sleep(600)
+
+def increment_count(fname):
+ try:
+ current_count = int(open(fname).read())
+ except:
+ current_count = 0
+ current_count += 1
+ open(fname, "w").write("%i\n" % current_count)
+ return current_count
+
+if __name__ == '__main__':
+ from optparse import OptionParser
+
+ parser = OptionParser(__doc__)
+ parser.add_option("-n", "--max-count", dest="maxcount", default=10,
+ help="reboot after <maxcount> runs", type="int")
+ parser.add_option("-f", "--count-file", dest="countfile", default=None,
+ help="file to record count in")
+ parser.add_option("-z", "--zero-count", dest="zero", default=False,
+ action="store_true", help="zero out the counter before rebooting")
+
+ options, args = parser.parse_args()
+
+ if not options.countfile:
+ parser.error("countfile is required")
+
+ if increment_count(options.countfile) >= options.maxcount:
+ if options.zero:
+ open(options.countfile, "w").write("0\n")
+ print "************************************************************************************************"
+ print "*********** END OF RUN - NOW DOING SCHEDULED REBOOT; FOLLOWING ERROR MESSAGE EXPECTED **********"
+ print "************************************************************************************************"
+ sys.stdout.flush()
+ reboot()