-
Notifications
You must be signed in to change notification settings - Fork 1
/
houndour.py
42 lines (36 loc) · 1.47 KB
/
houndour.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
import rotom
import json
import docker
import time
import subprocess
def do_startup(script_path: str):
print(f'[Houndour] running startup script at {script_path}')
subprocess.check_output('bash ' + script_path, shell=True).decode('utf-8')
print(f'[Houndour] ran startup script')
if __name__ == '__main__':
with open('houndour.json') as f:
config = json.load(f)
rotom_client = rotom.Rotom(config)
docker_client = docker.from_env()
print('[Houndour] started, sleeping for 30 seconds')
time.sleep(30)
do_startup(rotom_client.get_startup_script())
while True:
rotom_client.get_status_page()
needs_reboot = rotom_client.get_reboot_needed()
if needs_reboot is not None:
if len(needs_reboot) == 0:
print('[Houndour] all devices alive')
for device in needs_reboot:
print(f'[Houndour] {device["deviceName"]} needs to be restarted')
restarted = False
for container in docker_client.containers.list():
if container.name == device['dockerName']:
container.restart()
restarted = True
break
if restarted:
print(f'[Houndour] {device["deviceName"]} sucessfully restarted')
else:
print(f'[Houndour] {device["deviceName"]} container not found')
time.sleep(rotom_client.get_check_interval())