Index: server/site_system_suspend.py |
diff --git a/server/site_system_suspend.py b/server/site_system_suspend.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cf2d058ed149efafcaa04b9079b112df2863707f |
--- /dev/null |
+++ b/server/site_system_suspend.py |
@@ -0,0 +1,32 @@ |
+#!/usr/bin/python |
+ |
+"""Tell system to suspend, and resume some number of seconds later. |
+ |
+Use the RTC to generate a wakeup some number of seconds into the |
+future, then go to sleep. Note that this module is not aware of |
+the actual time when the system will suspend. Depending on other |
+system activities, there may be several seconds between when this |
+script runs until when the system actually goes to sleep. In fact |
+that time may be after the wakeup has been scheduled, and the |
+system may never wake up! It is up to the caller to make prudent |
+decisions as to upper bound of delay before going to sleep, and to |
+choose a wakeup time greater than this interval. |
+""" |
+ |
+import os, re, subprocess, sys |
+import rtc, sys_power |
+ |
+time_to_sleep = 30 |
+if len(sys.argv) > 1: |
+ time_to_sleep = int(sys.argv[1]) |
+ |
+if len(sys.argv) > 2: |
+ after_command = ' '.join(sys.argv[2:]) |
+else: |
+ after_command = None |
+ |
+rtc.set_wake_alarm(rtc.get_seconds() + time_to_sleep) |
+sys_power.suspend_to_ram() |
+ |
+if after_command: |
+ os.system(after_command) |