-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
52 lines (40 loc) · 1.77 KB
/
run.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
#!/usr/bin/env python3
import argparse
import os
import sys
from app.library.daemon import Daemon
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--debug", help="enable debug mode (does not work with daemon mode)", action="store_true", default=False)
daemon_group = parser.add_argument_group("daemon")
daemon_group.add_argument("--daemon", help="run in daemon mode", action="store_true", default=False)
daemon_group.add_argument("--stop", help="stop if running in daemon mode", action="store_true", default=False)
daemon_group.add_argument("--restart", help="restart daemon", action="store_true", default=False)
web_frontend_group = parser.add_argument_group("net")
web_frontend_group.add_argument("--port", default=7000, help="port at which the web frontend is listening", type=int)
web_frontend_group.add_argument("--host", default="127.0.0.1",
help="host IP under which the web front end is listening")
args = parser.parse_args()
from app import app, socketio
class Application(Daemon):
def start(self):
if sys.platform == "win32":
print("Sorry, but daemon mode is not supported under Windows!")
sys.exit(1)
super().start()
return
def run(self):
socketio.run(app, host=args.host, port=args.port, debug=args.debug)
application = Application(os.path.join(app.config["DATA_PATH"], "pyencode.pid"))
if args.restart:
application.restart()
elif args.stop:
application.stop()
else:
if args.daemon:
application.start()
else:
# check if pyEncode is already running
try:
application.run()
except OSError:
sys.stderr.write("pyEncode is already running (maybe as daemon?)\n")