-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptminder-hat.py
executable file
·55 lines (42 loc) · 1.53 KB
/
scriptminder-hat.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
49
50
51
52
53
54
55
#!/usr/bin/python3
"""
A script that runs periodically to ensure that the tester is configured correctly
"""
import subprocess
import psutil
import time
import RPi.GPIO as GPIO
SCRIPT='hat-test' # the last letters are truncated, because linux sucks
def checkIfProcessRunning(processName):
'''
Check if there is any running process that contains the given name processName.
'''
#Iterate over the all the running process
for proc in psutil.process_iter():
try:
#print(proc.name())
# Check if process name contains the given name string.
if processName.lower() in proc.name().lower():
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
return False;
def killScript(processName):
for proc in psutil.process_iter():
if processName in proc.name():
print(processName + " found in table, killing: " + proc.name())
proc.kill()
def main():
global SCRIPT
time.sleep(3) # some time for boot stuff to complete
while True:
if checkIfProcessRunning(SCRIPT):
print(SCRIPT + " is running, sleeping!")
time.sleep(3)
else:
print(SCRIPT + " is not running, restarting it!")
killScript(SCRIPT) # just in case, so we don't have multiple copies
subprocess.run(['/home/precursor/code/bootstrap-mainboard/hat-test.py'])
time.sleep(3)
if __name__ == '__main__':
main()