-
Notifications
You must be signed in to change notification settings - Fork 4
/
freedom_keep_alive.py
48 lines (34 loc) · 1.21 KB
/
freedom_keep_alive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import time
import logging
import subprocess
def execute(cmd):
"""
Simple wrapper for executing command line
"""
try:
return subprocess.check_output(cmd, shell=True).strip().decode("utf-8")
except Exception as e:
return None
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
num_startup_failures = 0
while True:
# If it exited immediately, then we assume something happened
# on startup (Bad credentials, deleted device, etc) and so wait
# longer inbetween.
if num_startup_failures > 5:
time.sleep(60)
start_agent_time = time.time()
execute("service freedomrobotics start")
logger.info("freedomrobotics service started")
while True:
time.sleep(10)
result = execute("service freedomrobotics status")
if result is None or "is running" not in result:
logger.error("freedomrobotics service exited")
if time.time() - start_agent_time < 30:
num_startup_failures += 1
else:
num_startup_failures = 0
break