-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanager.py
More file actions
54 lines (46 loc) · 1.59 KB
/
manager.py
File metadata and controls
54 lines (46 loc) · 1.59 KB
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
# coding: utf-8
"""
@Author: Robby
@Module name:
@Create date: 2020-11-17
@Function:
"""
import sys
import os
import signal
from daemonization import Daemonize
from utils.const_file import PID_FILE, ENGILE_LOG
from utils.global_logger import getlogger
from tasks import start_engine
engile_logger = getlogger(logger_name='engine', info_file_path=ENGILE_LOG, error_file_path=ENGILE_LOG)
if len(sys.argv) != 2:
print('Usage:python {} [start|stop]'.format(sys.argv[0]), file=sys.stderr)
raise SystemExit(1)
if sys.argv[1] == 'start':
try:
daemon = Daemonize(pidfile=PID_FILE, stdout=ENGILE_LOG, stderr=ENGILE_LOG)
daemon.start()
print('Engine Start Success', file=sys.stdout)
engile_logger.info('Engine Start Success')
except RuntimeError as e:
engile_logger.error('Engine Start Error, Message: {}'.format(e))
raise SystemExit(1)
start_engine()
elif sys.argv[1] == 'stop':
if os.path.exists(PID_FILE):
try:
with open(PID_FILE) as f:
os.kill(int(f.read()), signal.SIGKILL)
os.remove(PID_FILE)
print('Engine Stop Success', file=sys.stdout)
engile_logger.info('Engine Stop Success')
except Exception as e:
with open(PID_FILE) as f:
os.kill(int(f.read()), signal.SIGTERM)
engile_logger.error('Engine Stop Fail, Message: {}'.format(e))
else:
print('Engine Not Running', file=sys.stderr)
raise SystemExit(1)
else:
print('Unknown command {}'.format(sys.argv[1]), file=sys.stderr)
raise SystemExit(1)