-
Notifications
You must be signed in to change notification settings - Fork 0
/
jamid.py
30 lines (26 loc) · 989 Bytes
/
jamid.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
import os
import psutil
import subprocess
import time
def is_daemon_running():
for proc in psutil.process_iter():
if proc.name() == "jamid":
return True
return False
def start_daemon(debug=False):
# Run jami daemon, piping colored outputs to specified log file
print("Starting jamid")
debug_flag = ""
if debug:
debug_flag = "-d"
command = f'script -qfc "/usr/local/lib/arm-linux-gnueabihf/jamid {debug_flag} --auto-answer -c" /home/pi/log.txt > /dev/null'
print("Watch output with 'tail -f ~/log.txt'")
subprocess.Popen(command, shell=True, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(3)
def reset():
for proc in psutil.process_iter():
if proc.name() == "jamid":
print("Terminating jamid")
proc.terminate()
# Start daemon once old process terminates
psutil.wait_procs([proc], timeout=3, callback=start_daemon)