pull/109/head
midoks 3 years ago
parent ad583f1cb4
commit ca659eb4f1
  1. 2
      .gitignore
  2. 9
      app.py
  3. 7
      class/core/system_api.py
  4. 2
      route/static/app/config.js
  5. 35
      scripts/init.d/mw.tpl
  6. 6
      setting.py
  7. 77
      task.py

2
.gitignore vendored

@ -133,3 +133,5 @@ data/ssl.pl
data/port.pl data/port.pl
plugins/openlitespeed plugins/openlitespeed
plugins/gdrive/ plugins/gdrive/
data/ipv6.pl
data/restart.pl

@ -14,13 +14,22 @@ from geventwebsocket.handler import WebSocketHandler
try: try:
if __name__ == "__main__": if __name__ == "__main__":
PORT = 7200
if os.path.exists('data/port.pl'):
f = open('data/port.pl') f = open('data/port.pl')
PORT = int(f.read()) PORT = int(f.read())
f.close()
HOST = '0.0.0.0' HOST = '0.0.0.0'
if os.path.exists('data/ipv6.pl'):
HOST = "::1"
http_server = WSGIServer( http_server = WSGIServer(
(HOST, PORT), app, handler_class=WebSocketHandler) (HOST, PORT), app, handler_class=WebSocketHandler)
http_server.serve_forever() http_server.serve_forever()
socketio.run(app, host=HOST, port=PORT) socketio.run(app, host=HOST, port=PORT)
except Exception as ex: except Exception as ex:
print(ex) print(ex)

@ -102,12 +102,9 @@ class system_api:
return mw.returnJson(True, '正在重启服务器!') return mw.returnJson(True, '正在重启服务器!')
##### ----- end ----- ### ##### ----- end ----- ###
@mw_async
def restartMw(self): def restartMw(self):
sleep(0.3) mw.writeFile('data/restart.pl', 'True')
# cmd = mw.getRunDir() + '/scripts/init.d/mw restart' return True
# print cmd
mw.execShell('service mw restart')
@mw_async @mw_async
def restartServer(self): def restartServer(self):

@ -209,7 +209,7 @@ function setIPv6() {
$.post('/config/set_ipv6_status', {}, function (rdata) { $.post('/config/set_ipv6_status', {}, function (rdata) {
layer.close(loadT); layer.close(loadT);
layer.msg(rdata.msg, {icon:rdata.status?1:2}); layer.msg(rdata.msg, {icon:rdata.status?1:2});
setTimeout(function(){window.location.reload();},1500); setTimeout(function(){window.location.reload();},5000);
},'json'); },'json');
} }

@ -26,11 +26,11 @@ else
echo "" echo ""
fi fi
mw_start_panel()
mw_start(){ {
isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'` isStart=`ps -ef|grep 'gunicorn -c setting.py app:app' |grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "Starting mw... \c" echo -e "Starting mw Panel... \c"
cd $mw_path && gunicorn -c setting.py app:app cd $mw_path && gunicorn -c setting.py app:app
port=$(cat ${mw_path}/data/port.pl) port=$(cat ${mw_path}/data/port.pl)
isStart="" isStart=""
@ -49,15 +49,18 @@ mw_start(){
echo '------------------------------------------------------' echo '------------------------------------------------------'
tail -n 20 ${mw_path}/logs/error.log tail -n 20 ${mw_path}/logs/error.log
echo '------------------------------------------------------' echo '------------------------------------------------------'
echo -e "\033[31mError: mw service startup failed.\033[0m" echo -e "\033[31mError: mw Panel service startup failed.\033[0m"
return; return;
fi fi
echo -e "\033[32mdone\033[0m" echo -e "\033[32mdone\033[0m"
else else
echo "Starting mw... mw(pid $(echo $isStart)) already running" echo "Starting mw Panel... mw(pid $(echo $isStart)) already running"
fi fi
}
mw_start_task()
{
isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}') isStart=$(ps aux |grep 'task.py'|grep -v grep|awk '{print $2}')
if [ "$isStart" == '' ];then if [ "$isStart" == '' ];then
echo -e "Starting mw-tasks... \c" echo -e "Starting mw-tasks... \c"
@ -78,8 +81,14 @@ mw_start(){
fi fi
} }
mw_start()
{
mw_start_panel
mw_start_task
}
mw_stop()
mw_stop_task()
{ {
echo -e "Stopping mw-tasks... \c"; echo -e "Stopping mw-tasks... \c";
pids=$(ps aux | grep 'task.py'|grep -v grep|awk '{print $2}') pids=$(ps aux | grep 'task.py'|grep -v grep|awk '{print $2}')
@ -90,8 +99,11 @@ mw_stop()
kill -9 $p kill -9 $p
done done
echo -e "\033[32mdone\033[0m" echo -e "\033[32mdone\033[0m"
}
echo -e "Stopping mw... \c"; mw_stop_panel()
{
echo -e "Stopping mw Panel... \c";
arr=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'` arr=`ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}'`
for p in ${arr[@]} for p in ${arr[@]}
do do
@ -104,6 +116,12 @@ mw_stop()
echo -e "\033[32mdone\033[0m" echo -e "\033[32mdone\033[0m"
} }
mw_stop()
{
mw_stop_panel
mw_stop_task
}
mw_status() mw_status()
{ {
isStart=$(ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}') isStart=$(ps aux|grep 'gunicorn -c setting.py app:app'|grep -v grep|awk '{print $2}')
@ -163,6 +181,9 @@ case "$1" in
'restart') 'restart')
mw_stop mw_stop
mw_start;; mw_start;;
'restart_panel')
mw_stop_panel
mw_start_panel;;
'status') mw_status;; 'status') mw_status;;
'logs') error_logs;; 'logs') error_logs;;
'default') 'default')

@ -34,10 +34,10 @@ else:
mw.writeFile('data/port.pl', mw_port) mw.writeFile('data/port.pl', mw_port)
bind = [] bind = []
if os.path.exists('data/ipv6.pl'):
bind.append('[0:0:0:0:0:0:0:0]:%s' % mw_port)
else:
bind.append('0.0.0.0:%s' % mw_port) bind.append('0.0.0.0:%s' % mw_port)
if os.path.exists('data/ipv6.pl'):
bind.append('[::1]:%s' % mw_port)
if workers > 2: if workers > 2:
workers = 2 workers = 2

@ -25,7 +25,6 @@ import db
import psutil import psutil
global pre, timeoutCount, logPath, isTask, oldEdate, isCheck global pre, timeoutCount, logPath, isTask, oldEdate, isCheck
pre = 0 pre = 0
timeoutCount = 0 timeoutCount = 0
@ -45,6 +44,18 @@ if not os.path.exists(isTask):
os.system("touch " + isTask) os.system("touch " + isTask)
def service_cmd(method):
cmd = '/etc/init.d/mw'
if os.path.exists(cmd):
execShell(cmd + ' ' + method)
return
cmd = mw.getRunDir() + '/scripts/init.d/mw'
if os.path.exists(cmd):
execShell(cmd + ' ' + method)
return
def mw_async(f): def mw_async(f):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
thr = threading.Thread(target=f, args=args, kwargs=kwargs) thr = threading.Thread(target=f, args=args, kwargs=kwargs)
@ -94,7 +105,7 @@ def execShell(cmdstring, cwd=None, timeout=None, shell=True):
t2 = str(data[1], encoding='utf-8') t2 = str(data[1], encoding='utf-8')
return (t1, t2) return (t1, t2)
except Exception as e: except Exception as e:
return None return (None, None)
def downloadFile(url, filename): def downloadFile(url, filename):
@ -168,32 +179,12 @@ def startTask():
except: except:
pass pass
# siteEdate() # siteEdate()
# mainSafe()
time.sleep(2) time.sleep(2)
except: except:
time.sleep(60) time.sleep(60)
startTask() startTask()
def mainSafe():
global isCheck
try:
if isCheck < 100:
isCheck += 1
return True
isCheck = 0
isStart = mw.execShell(
"ps aux |grep 'python3 main.py'|grep -v grep|awk '{print $2}'")[0]
if not isStart:
os.system('/etc/init.d/mw start')
isStart = mw.execShell(
"ps aux |grep 'python main.py'|grep -v grep|awk '{print $2}'")[0]
mw.writeLog('守护程序', '面板服务程序启动成功 -> PID: ' + isStart)
except:
time.sleep(30)
mainSafe()
def siteEdate(): def siteEdate():
# 网站到期处理 # 网站到期处理
global oldEdate global oldEdate
@ -508,30 +499,44 @@ def openrestyAutoRestart():
# --------------------------------------OpenResty Auto Restart End --------------------------------------------- # # --------------------------------------OpenResty Auto Restart End --------------------------------------------- #
if __name__ == "__main__": # --------------------------------------Panel Restart Start --------------------------------------------- #
def restartPanelService():
restartTip = 'data/restart.pl'
while True:
if os.path.exists(restartTip):
os.remove(restartTip)
service_cmd('restart_panel')
time.sleep(1)
# --------------------------------------Panel Restart End --------------------------------------------- #
# 系统监控
t = threading.Thread(target=systemTask) def setDaemon(t):
if sys.version_info.major == 3 and sys.version_info.minor >= 10: if sys.version_info.major == 3 and sys.version_info.minor >= 10:
t.daemon = True t.daemon = True
else: else:
t.setDaemon(True) t.setDaemon(True)
t.start() return t
if __name__ == "__main__":
# 系统监控
sysTask = threading.Thread(target=systemTask)
sysTask = setDaemon(sysTask)
sysTask.start()
# PHP 502错误检查线程 # PHP 502错误检查线程
p = threading.Thread(target=check502Task) php502 = threading.Thread(target=check502Task)
if sys.version_info.major == 3 and sys.version_info.minor >= 10: php502 = setDaemon(php502)
p.daemon = True php502.start()
else:
p.setDaemon(True)
p.start()
# OpenResty Auto Restart Start # OpenResty Auto Restart Start
oar = threading.Thread(target=openrestyAutoRestart) oar = threading.Thread(target=openrestyAutoRestart)
if sys.version_info.major == 3 and sys.version_info.minor >= 10: oar = setDaemon(oar)
oar.daemon = True
else:
oar.setDaemon(True)
oar.start() oar.start()
# OpenResty Auto Restart Start
rps = threading.Thread(target=restartPanelService)
rps = setDaemon(rps)
rps.start()
startTask() startTask()

Loading…
Cancel
Save