-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlauncher.py
104 lines (91 loc) · 2.9 KB
/
launcher.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name: launcher
Description : 启动器
Author : 007x
date: 2021/3/26
-------------------------------------------------
Change Activity:
2021/3/26: 启动器
-------------------------------------------------
"""
__author__ = '007x'
import os
import sys
import signal
import daemon
from daemon.pidfile import PIDLockFile
from db.dbClient import DbClient
from handler.logHandler import LogHandler
from handler.configHandler import ConfigHandler
log = LogHandler('launcher')
conf = ConfigHandler()
def startServerProcess():
__beforeStart()
from api.proxyApi import runFlask
with daemon.DaemonContext(
#stdout=sys.stdout, stderr=sys.stderr,
working_directory='./',
pidfile=PIDLockFile(conf.serverPidFile),
umask=0o022,
detach_process=True):
runFlask()
#runFlask()
def stopServerProcess():
try:
with open(conf.serverPidFile, "r") as f:
pid = int(f.read().strip())
os.kill(pid, signal.SIGTERM)
os.remove(conf.serverPidFile)
print(f"Server process: {pid} stoped")
#print("Server pid file removed")
except FileNotFoundError:
pass
except ProcessLookupError:
pass
def startSchedulerProcess():
__beforeStart()
from helper.scheduler import runScheduler
with daemon.DaemonContext(
#stdout=sys.stdout, stderr=sys.stderr,
working_directory='./',
pidfile=PIDLockFile(conf.schedulerPidFile),
umask=0o022,
detach_process=True):
runScheduler()
def stopSchedulerProcess():
try:
with open(conf.schedulerPidFile, "r") as f:
pid = int(f.read().strip())
os.kill(pid, signal.SIGTERM)
os.remove(conf.schedulerPidFile)
print(f"Server process: {pid} stoped")
#print("Server pid file removed")
except FileNotFoundError:
pass
except ProcessLookupError:
pass
def __beforeStart():
__showVersion()
__showConfigure()
if __checkDBConfig():
log.info('exit!')
sys.exit()
def __showVersion():
from setting import VERSION
log.info("ProxyPool Version: %s" % VERSION)
def __showConfigure():
log.info("ProxyPool configure HOST: %s" % conf.serverHost)
log.info("ProxyPool configure PORT: %s" % conf.serverPort)
log.info("ProxyPool configure PROXY_FETCHER: %s" % conf.fetchers)
def __checkDBConfig():
db = DbClient(conf.dbConn)
log.info("============ DATABASE CONFIGURE ================")
log.info("DB_TYPE: %s" % db.db_type)
log.info("DB_HOST: %s" % db.db_host)
log.info("DB_PORT: %s" % db.db_port)
log.info("DB_NAME: %s" % db.db_name)
log.info("DB_USER: %s" % db.db_user)
log.info("=================================================")
return db.test()