-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-snet-service.py
executable file
·48 lines (36 loc) · 1.28 KB
/
run-snet-service.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 pathlib
import subprocess
import signal
import time
import sys
import argparse
def main():
parser = argparse.ArgumentParser(prog="run-snet-service")
parser.add_argument("--daemon-config-path", help="Path to daemon configuration file", required=False)
args = parser.parse_args(sys.argv[1:])
def handle_signal(signum, frame):
snetd_p.send_signal(signum)
service_p.send_signal(signum)
snetd_p.wait()
service_p.wait()
exit(0)
signal.signal(signal.SIGTERM, handle_signal)
signal.signal(signal.SIGINT, handle_signal)
root_path = pathlib.Path(__file__).absolute().parent.parent
snetd_p = start_snetd(root_path, args.daemon_config_path)
service_p = start_service(root_path)
while True:
if snetd_p.poll() is not None:
snetd_p = start_snetd(root_path, args.daemon_config_path)
if service_p.poll() is not None:
service_p = start_service(root_path)
time.sleep(5)
def start_snetd(cwd, daemon_config_path=None):
cmd = ["snetd"]
if daemon_config_path is not None:
cmd.extend(["--config-path", daemon_config_path])
return subprocess.Popen(cmd)
def start_service(cwd):
return subprocess.Popen(["python", "script.py"])
if __name__ == "__main__":
main()