diff --git a/LICENSE b/LICENSE index 261eeb9e9..f37a89ca4 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright [midoks] [midoks of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/class/core/mw.py b/class/core/mw.py index 5629d57ac..f8fa5ccf7 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -98,6 +98,23 @@ def isAppleSystem(): return False +def isNumber(s): + try: + float(s) + return True + except ValueError: + pass + + try: + import unicodedata + unicodedata.numeric(s) + return True + except (TypeError, ValueError): + pass + + return False + + def deleteFile(file): if os.path.exists(file): os.remove(file) diff --git a/class/core/plugins_api.py b/class/core/plugins_api.py index 3a22894f6..26f70906e 100755 --- a/class/core/plugins_api.py +++ b/class/core/plugins_api.py @@ -48,6 +48,13 @@ class plugins_api: def listApi(self): sType = request.args.get('type', '0') sPage = request.args.get('p', '1') + + if not mw.isNumber(sPage): + sPage = 1 + + if not mw.isNumber(sType): + sType = 0 + # print sPage data = self.getPluginList(sType, int(sPage)) return mw.getJson(data) diff --git a/class/core/site_api.py b/class/core/site_api.py index 9ab00f1dc..6978c96e1 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -599,7 +599,11 @@ class site_api: if not os.path.exists(acem): return mw.returnJson(False, '尝试自动安装ACME失败,请通过以下命令尝试手动安装

安装命令: curl https://get.acme.sh | sh

' + acem) - force_bool = False + # 避免频繁执行 + checkAcmeRun = mw.execShell('ps -ef|grep acme.sh |grep -v grep') + if checkAcmeRun[0] != '': + return mw.returnJson(False, '正在申请或更新SSL中...') + if force == 'true': force_bool = True @@ -973,7 +977,7 @@ class site_api: "-START(.|\n)+BINDING-" + domain + "-END" tmp = re.search(rep, conf).group() dirConf = tmp.replace('rewrite/' + site['name'] + '.conf;', 'rewrite/' + site[ - 'name'] + '_' + find['path'] + '.conf;') + 'name'] + '_' + find['path'] + '.conf;') conf = conf.replace(tmp, dirConf) mw.writeFile(file, conf) data = {} diff --git a/plugins/openresty/index.py b/plugins/openresty/index.py index 8875bb4e7..121190493 100755 --- a/plugins/openresty/index.py +++ b/plugins/openresty/index.py @@ -267,7 +267,21 @@ def initdUinstall(): def runInfo(): # 取Openresty负载状态 try: - result = mw.httpGet('http://127.0.0.1/nginx_status') + url = 'http://' + mw.getHostAddr() + '/nginx_status' + result = mw.httpGet(url) + tmp = result.split() + data = {} + data['active'] = tmp[2] + data['accepts'] = tmp[9] + data['handled'] = tmp[7] + data['requests'] = tmp[8] + data['Reading'] = tmp[11] + data['Writing'] = tmp[13] + data['Waiting'] = tmp[15] + return mw.getJson(data) + except Exception as e: + url = 'http://127.0.0.1/nginx_status' + result = mw.httpGet(url) tmp = result.split() data = {} data['active'] = tmp[2] diff --git a/plugins/openresty/install.sh b/plugins/openresty/install.sh index 53ae30979..92954192e 100755 --- a/plugins/openresty/install.sh +++ b/plugins/openresty/install.sh @@ -24,6 +24,7 @@ else useradd -g www -s /bin/bash www fi +# cd /www/server/mdserver-web/plugins/openresty && /bin/bash install.sh install 1.21.4.1 Install_openresty() { mkdir -p ${openrestyDir} @@ -37,13 +38,19 @@ Install_openresty() cd ${openrestyDir} && tar -zxvf openresty-${VERSION}.tar.gz # --with-openssl=$serverPath/source/lib/openssl-1.0.2q - cd ${openrestyDir}/openresty-${VERSION} && ./configure --prefix=$serverPath/openresty \ + cd ${openrestyDir}/openresty-${VERSION} && ./configure \ + --prefix=$serverPath/openresty \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_slice_module \ - --with-http_stub_status_module && make && make install && \ - echo "${VERSION}" > $serverPath/openresty/version.pl - echo "" > $serverPath/web_conf/nginx/enable-php-00.conf + --with-http_stub_status_module + + gmake && gmake install && make clean + + if [ -d $serverPath/openresty ];then + echo "${VERSION}" > $serverPath/openresty/version.pl + echo "" > $serverPath/openresty/nginx/conf/enable-php-00.conf + fi echo '安装完成' > $install_tmp } diff --git a/plugins/php/index.py b/plugins/php/index.py index d23cfdff6..fe6be8eca 100755 --- a/plugins/php/index.py +++ b/plugins/php/index.py @@ -521,25 +521,38 @@ def setFpmConfig(version): def checkFpmStatusFile(version): - if mw.isInstalledWeb(): - sdir = mw.getServerDir() - dfile = sdir + '/openresty/nginx/conf/php_status/phpfpm_status_' + version + '.conf' - if not os.path.exists(dfile): - tpl = getPluginDir() + '/conf/phpfpm_status.conf' - content = mw.readFile(tpl) - content = contentReplace(content, version) - mw.writeFile(dfile, content) - mw.restartWeb() + if not mw.isInstalledWeb(): + return False + + dfile = getServerDir() + '/nginx/conf/php_status/phpfpm_status_' + version + '.conf' + if not os.path.exists(dfile): + tpl = getPluginDir() + '/conf/phpfpm_status.conf' + content = mw.readFile(tpl) + content = contentReplace(content, version) + mw.writeFile(dfile, content) + mw.restartWeb() + return True def getFpmStatus(version): checkFpmStatusFile(version) - result = mw.httpGet( - 'http://127.0.0.1/phpfpm_status_' + version + '?json') - tmp = json.loads(result) - fTime = time.localtime(int(tmp['start time'])) - tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime) - return mw.getJson(tmp) + + try: + url = 'http://' + mw.getHostAddr() + '/phpfpm_status_' + version + '?json' + result = mw.httpGet(url) + data = json.loads(result) + fTime = time.localtime(int(data['start time'])) + data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime) + except Exception as e: + url = 'http://127.0.0.1/phpfpm_status_' + version + '?json' + result = mw.httpGet(url) + data = json.loads(result) + fTime = time.localtime(int(data['start time'])) + data['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime) + except Exception as e: + data = {} + + return mw.getJson(data) def getDisableFunc(version): diff --git a/plugins/php/lib/zlib.sh b/plugins/php/lib/zlib.sh index 56e159a18..ab6b4c50a 100644 --- a/plugins/php/lib/zlib.sh +++ b/plugins/php/lib/zlib.sh @@ -13,7 +13,7 @@ rootPath=$(dirname "$rootPath") SERVER_ROOT=$rootPath/lib SOURCE_ROOT=$rootPath/source/lib -if [ ! -d ${SERVER_ROOT}/libiconv ];then +if [ ! -d ${SERVER_ROOT}/zlib ];then cd $SOURCE_ROOT if [ ! -f ${SOURCE_ROOT}/zlib-1.2.11.tar.gz ];then diff --git a/plugins/php/versions/52/install.sh b/plugins/php/versions/52/install.sh index 5bacea599..9cdb35703 100755 --- a/plugins/php/versions/52/install.sh +++ b/plugins/php/versions/52/install.sh @@ -11,6 +11,46 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl + +_os=`uname` +echo "use system: ${_os}" + +if [ ${_os} == "Darwin" ]; then + OSNAME='macos' +elif grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then + OSNAME='centos' +elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then + OSNAME='fedora' +elif grep -Eqi "Rocky" /etc/issue || grep -Eq "Rocky" /etc/*-release; then + OSNAME='rocky' +elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then + OSNAME='alma' +elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then + OSNAME='debian' +elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then + OSNAME='ubuntu' +elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then + OSNAME='raspbian' +else + OSNAME='unknow' +fi + + +if [ "$OSNAME" == 'ubuntu' ] || [ "$OSNAME" == 'debian' ] ;then + apt install bison=2.4.1 + if [ "$?" != "0" ]; then + echo 'The system version is too high to install' + exit 1 + fi + + apt install flex=2.5.4 + if [ "$?" != "0" ]; then + echo 'The system version is too high to install' + exit 1 + fi +fi + + version=5.2.17 PHP_VER=52 Install_php() diff --git a/plugins/redis/index.py b/plugins/redis/index.py index 0a7f24910..5c57d2fef 100755 --- a/plugins/redis/index.py +++ b/plugins/redis/index.py @@ -96,9 +96,12 @@ def initDreplace(): # config replace dst_conf = getServerDir() + '/redis.conf' - conf_content = mw.readFile(getConfTpl()) - conf_content = conf_content.replace('{$SERVER_PATH}', service_path) - mw.writeFile(dst_conf, conf_content) + dst_conf_init = getServerDir() + '/init.pl' + if not os.path.exists(dst_conf_init): + conf_content = mw.readFile(getConfTpl()) + conf_content = conf_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(dst_conf, conf_content) + mw.writeFile(dst_conf_init, 'ok') # systemd systemDir = '/lib/systemd/system' diff --git a/plugins/varnish/index.html b/plugins/varnish/index.html index df23818be..d250b0686 100755 --- a/plugins/varnish/index.html +++ b/plugins/varnish/index.html @@ -4,6 +4,7 @@

服务

自启动

VCL

+

服务配置

日志

状态

diff --git a/plugins/varnish/index.py b/plugins/varnish/index.py index 21cfa828a..78f3df281 100755 --- a/plugins/varnish/index.py +++ b/plugins/varnish/index.py @@ -172,6 +172,10 @@ def initdUinstall(): def runLog(): return "/var/log/varnish/varnishncsa.log" + +def confService(): + return '/lib/systemd/system/varnish.service' + if __name__ == "__main__": func = sys.argv[1] if func == 'status': @@ -194,6 +198,8 @@ if __name__ == "__main__": print(runInfo()) elif func == 'conf': print(getConf()) + elif func == 'conf_service': + print(confService()) elif func == 'run_log': print(runLog()) elif func == 'config_tpl': diff --git a/plugins/varnish/js/varnish.js b/plugins/varnish/js/varnish.js index 607289aca..5a0ffbcec 100644 --- a/plugins/varnish/js/varnish.js +++ b/plugins/varnish/js/varnish.js @@ -9,7 +9,7 @@ function pRead(){ } -//redis负载状态 start +//varnish负载状态 start function varnishStatus() { var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); $.post('/plugins/run', {name:'varnish', func:'run_info'}, function(data) { @@ -41,4 +41,61 @@ function varnishStatus() { $(".soft-man-con").html(Con); },'json'); } -//redis负载状态 end \ No newline at end of file +//varnish负载状态 end + + +//varnish service --- +function varnishPluginConfig(_name, version, func){ + if ( typeof(version) == 'undefined' ){ + version = ''; + } + + var func_name = 'conf'; + if ( typeof(func) != 'undefined' ){ + func_name = func; + } + + var con = '

提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!

\ + \ + \ + '; + $(".soft-man-con").html(con); + + var loadT = layer.msg('配置文件路径获取中...',{icon:16,time:0,shade: [0.3, '#000']}); + $.post('/plugins/run', {name:_name, func:func_name,version:version},function (data) { + layer.close(loadT); + + var loadT2 = layer.msg('文件内容获取中...',{icon:16,time:0,shade: [0.3, '#000']}); + var fileName = data.data; + $.post('/files/get_body', 'path=' + fileName, function(rdata) { + layer.close(loadT2); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + $("#textBody").empty().text(rdata.data.data); + $(".CodeMirror").remove(); + var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { + extraKeys: { + "Ctrl-Space": "autocomplete", + "Ctrl-F": "findPersistent", + "Ctrl-H": "replaceAll", + "Ctrl-S": function() { + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + } + }, + lineNumbers: true, + matchBrackets:true, + }); + editor.focus(); + $(".CodeMirror-scroll").css({"height":"300px","margin":0,"padding":0}); + $("#onlineEditFileBtn").click(function(){ + $("#textBody").text(editor.getValue()); + pluginConfigSave(fileName); + }); + },'json'); + },'json'); +} diff --git a/requirements.txt b/requirements.txt index 9f607da48..4b1870f88 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,6 @@ zmq==0.0.0 pymongo pillow Jinja2>=2.11.2 -mysqlclient>=2.0.3 flask-caching>=1.10.1 mysql-connector-python +mysqlclient>=2.0.3 diff --git a/route/static/app/soft.js b/route/static/app/soft.js index 34b3f3c37..020a19933 100755 --- a/route/static/app/soft.js +++ b/route/static/app/soft.js @@ -33,7 +33,7 @@ function getSList(isdisplay) { var loadT = layer.msg('正在获取列表...', { icon: 16, time: 0, shade: [0.3, '#000'] }) } if (!isdisplay || isdisplay === true) - isdisplay = getCookie('p' + getCookie('softType')); + isdisplay = getCookie('p' + getCookie('soft_type')); if (isdisplay == true || isdisplay == 'true') isdisplay = 1; var search = $("#SearchValue").val(); @@ -41,7 +41,7 @@ function getSList(isdisplay) { search = '&search=' + search; } var type = ''; - var istype = getCookie('softType'); + var istype = getCookie('soft_type'); if (istype == 'undefined' || istype == 'null' || !istype) { istype = '0'; } @@ -50,7 +50,7 @@ function getSList(isdisplay) { var page = ''; if (isdisplay) { page = '&p=' + isdisplay; - setCookie('p' + getCookie('softType'), isdisplay); + setCookie('p' + getCookie('soft_type'), isdisplay); } var condition = (search + type + page).slice(1); @@ -162,7 +162,7 @@ function getSList(isdisplay) { sBody += pBody; $("#softList").html(sBody); $(".menu-sub span").click(function() { - setCookie('softType', $(this).attr('typeid')); + setCookie('soft_type', $(this).attr('typeid')); $(this).addClass("on").siblings().removeClass("on"); getSList(); }); diff --git a/scripts/install/debian.sh b/scripts/install/debian.sh index e5338111f..426b9c0ac 100644 --- a/scripts/install/debian.sh +++ b/scripts/install/debian.sh @@ -3,12 +3,21 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH LANG=en_US.UTF-8 +# RED='\e[1;31m' # 红色 +# GREEN='\e[1;32m' # 绿色 +# YELLOW='\e[1;33m' # 黄色 +# BLUE='\e[1;34m' # 蓝色 +# PURPLE='\e[1;35m' # 紫色 +# CYAN='\e[1;36m' # 蓝绿色 +# WHITE='\e[1;37m' # 白色 +# NC='\e[0m' # 没有颜色 apt update -y apt install -y wget curl lsof unzip apt install -y python3-pip +apt install -y python3-dev apt install -y python3-venv apt install -y cron @@ -60,16 +69,47 @@ fi systemctl stop firewalld +#fix zlib1g-dev fail +echo -e "\e[0;32mfix zlib1g-dev install question start\e[0m" +Install_TmpFile=/tmp/debian-fix-zlib1g-dev.txt +apt install -y zlib1g-dev > ${Install_TmpFile} +if [ "$?" != "0" ];then + ZLIB1G_BASE_VER=$(cat ${Install_TmpFile} | grep zlib1g | awk -F "=" '{print $2}' | awk -F ")" '{print $1}') + ZLIB1G_BASE_VER=`echo ${ZLIB1G_BASE_VER} | sed "s/^[ \s]\{1,\}//g;s/[ \s]\{1,\}$//g"` + # echo "1${ZLIB1G_BASE_VER}1" + echo -e "\e[1;31mapt install zlib1g=${ZLIB1G_BASE_VER} zlib1g-dev\e[0m" + echo "Y" | apt install zlib1g=${ZLIB1G_BASE_VER} zlib1g-dev +fi +rm -rf ${Install_TmpFile} +echo -e "\e[0;32mfix zlib1g-dev install question end\e[0m" + + +#fix libunwind-dev fail +echo -e "\e[0;32mfix libunwind-dev install question start\e[0m" +Install_TmpFile=/tmp/debian-fix-libunwind-dev.txt +apt install -y zlib1g-dev > ${Install_TmpFile} +if [ "$?" != "0" ];then + liblzma5_BASE_VER=$(cat ${Install_TmpFile} | grep liblzma-dev | awk -F "=" '{print $2}' | awk -F ")" '{print $1}') + liblzma5_BASE_VER=`echo ${liblzma5_BASE_VER} | sed "s/^[ \s]\{1,\}//g;s/[ \s]\{1,\}$//g"` + echo -e "\e[1;31mapt install liblzma5=${liblzma5_BASE_VER} libunwind-dev\e[0m" + echo "Y" | apt install liblzma5=${liblzma5_BASE_VER} libunwind-dev +fi +rm -rf ${Install_TmpFile} +echo -e "\e[0;32mfix libunwind-dev install question end\e[0m" + + cd /www/server/mdserver-web/scripts && bash lib.sh chmod 755 /www/server/mdserver-web/data + + if [ ! -f /usr/local/bin/pip3 ];then python3 -m pip install --upgrade pip setuptools wheel -i https://mirrors.aliyun.com/pypi/simple fi pip install --upgrade pip -pip install --upgrade setuptools +sed -i "/mysqlclient/d" /www/server/mdserver-web/requirements.txt cd /www/server/mdserver-web && pip3 install -r /www/server/mdserver-web/requirements.txt pip3 install gunicorn==20.1.0 @@ -77,24 +117,23 @@ pip3 install gevent==21.1.2 pip3 install gevent-websocket==0.10.1 pip3 install requests==2.20.0 pip3 install flask-caching==1.10.1 -pip3 install flask-socketio==5.2.0 pip3 install pymongo pip3 install psutil +pip3 install flask-socketio==5.2.0 if [ ! -f /www/server/mdserver-web/bin/activate ];then cd /www/server/mdserver-web && python3 -m venv . cd /www/server/mdserver-web && source /www/server/mdserver-web/bin/activate pip install --upgrade pip pip3 install -r /www/server/mdserver-web/requirements.txt - pip install --upgrade setuptools pip3 install gunicorn==20.1.0 pip3 install gevent==21.1.2 pip3 install gevent-websocket==0.10.1 pip3 install requests==2.20.0 pip3 install flask-caching==1.10.1 - pip3 install flask-socketio==5.2.0 pip3 install pymongo - pip3 install psutil + pip3 install psutil + pip3 install flask-socketio==5.2.0 fi diff --git a/scripts/install/ubuntu.sh b/scripts/install/ubuntu.sh index 9bec0dbdd..adf835437 100644 --- a/scripts/install/ubuntu.sh +++ b/scripts/install/ubuntu.sh @@ -9,6 +9,8 @@ apt update -y apt install -y wget curl lsof unzip apt install -y python3-pip apt install -y python3-venv +apt install -y python3-dev + apt install -y cron diff --git a/scripts/install_dev.sh b/scripts/install_dev.sh index 4b914988f..37462fa8b 100755 --- a/scripts/install_dev.sh +++ b/scripts/install_dev.sh @@ -44,6 +44,7 @@ elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; th yum install -y wget zip unzip elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then OSNAME='debian' + apt install -y devscripts apt install -y wget zip unzip elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then OSNAME='ubuntu' diff --git a/scripts/lib.sh b/scripts/lib.sh index 7f33fc0e7..cc8afa54d 100755 --- a/scripts/lib.sh +++ b/scripts/lib.sh @@ -295,16 +295,19 @@ elif [ "$OSNAME" == "ubuntu" ] || [ "$OSNAME" == "debian" ]; then apt install -y cmake automake make apt install -y webp scons - apt install -y lzma lzma-dev libunwind-dev + apt install -y lzma lzma-dev + apt install -y libunwind-dev apt install -y libpcre3 libpcre3-dev apt install -y openssl apt install -y libxml2 libxml2-dev libbz2-dev libmcrypt-dev libpspell-dev librecode-dev apt install -y libgmp-dev libgmp3-dev libreadline-dev libxpm-dev - apt install -y zlib1g-dev dia pkg-config - apt install -y libjpeg62-turbo-dev libjpeg-dev libpng-dev + apt install -y dia pkg-config + apt install -y zlib1g-dev + apt install -y libjpeg-dev libpng-dev apt install -y libfreetype6 + apt install -y libjpeg62-turbo-dev apt install -y libfreetype6-dev apt install -y libevent-dev libncurses5-dev libldap2-dev diff --git a/scripts/update/debian.sh b/scripts/update/debian.sh index 5029b36ca..1e2d8156c 100644 --- a/scripts/update/debian.sh +++ b/scripts/update/debian.sh @@ -21,6 +21,7 @@ fi pip install --upgrade pip pip install --upgrade setuptools +sed -i "/mysqlclient/d" /www/server/mdserver-web/requirements.txt cd /www/server/mdserver-web && pip3 install -r /www/server/mdserver-web/requirements.txt pip3 install gunicorn==20.1.0 diff --git a/task.py b/task.py index 62ba5f4ef..5cee97a14 100755 --- a/task.py +++ b/task.py @@ -75,7 +75,6 @@ def execShell(cmdstring, cwd=None, timeout=None, shell=True): import shlex import datetime import subprocess - import time if timeout: end_time = datetime.datetime.now() + datetime.timedelta(seconds=timeout) @@ -226,7 +225,6 @@ def systemTask(): try: import system_api import psutil - import time sm = system_api.system_api() filename = 'data/control.conf' @@ -368,7 +366,7 @@ def systemTask(): mw.writeFile('logs/sys_interrupt.pl', str(ex)) restartMw() - import time + time.sleep(30) systemTask() @@ -388,17 +386,18 @@ def check502Task(): def check502(): try: - phpversions = ['53', '54', '55', '56', '70', '71', '72', '73', '74'] - for version in phpversions: + verlist = ['52', '53', '54', '55', '56', '70', + '71', '72', '73', '74', '80', '81'] + for ver in verlist: sdir = mw.getServerDir() - php_path = sdir + '/php/' + version + '/sbin/php-fpm' + php_path = sdir + '/php/' + ver + '/sbin/php-fpm' if not os.path.exists(php_path): continue - if checkPHPVersion(version): + if checkPHPVersion(ver): continue - if startPHPVersion(version): - print('检测到PHP-' + version + '处理异常,已自动修复!') - mw.writeLog('PHP守护程序', '检测到PHP-' + version + '处理异常,已自动修复!') + if startPHPVersion(ver): + print('检测到PHP-' + ver + '处理异常,已自动修复!') + mw.writeLog('PHP守护程序', '检测到PHP-' + ver + '处理异常,已自动修复!') except Exception as e: print(str(e)) @@ -452,8 +451,8 @@ def checkPHPVersion(version): try: url = 'http://127.0.0.1/phpfpm_status_' + version result = mw.httpGet(url) - # print version,result - # 检查nginx + # print(version,result) + # 检查openresty if result.find('Bad Gateway') != -1: return False if result.find('HTTP Error 404: Not Found') != -1: @@ -466,17 +465,52 @@ def checkPHPVersion(version): isStatus = mw.readFile(isTask) if isStatus == 'True': return True - filename = '/etc/init.d/openresty' - if os.path.exists(filename): - os.system(filename + ' start') + + # systemd + systemd = '/lib/systemd/system/openresty.service' + if os.path.exists(systemd): + execShell('systemctl reload openresty') + return True + # initd + initd = '/etc/init.d/openresty' + if os.path.exists(initd): + os.system(initd + ' reload') return True except: return True # --------------------------------------PHP监控 end--------------------------------------------- # + +# --------------------------------------OpenResty Auto Restart Start --------------------------------------------- # +# 解决acme.sh续签后,未起效。 +def openrestyAutoRestart(): + try: + while True: + # 检查是否安装 + odir = mw.getServerDir() + '/openresty' + if not os.path.exists(odir): + time.sleep(86400) + continue + + # systemd + systemd = '/lib/systemd/system/openresty.service' + initd = '/etc/init.d/openresty' + if os.path.exists(systemd): + execShell('systemctl reload openresty') + elif os.path.exists(initd): + os.system(initd + ' reload') + time.sleep(86400) + except Exception as e: + print(str(e)) + time.sleep(86400) + +# --------------------------------------OpenResty Auto Restart End --------------------------------------------- # + + if __name__ == "__main__": + # 系统监控 t = threading.Thread(target=systemTask) if sys.version_info.major == 3 and sys.version_info.minor >= 10: t.daemon = True @@ -484,12 +518,20 @@ if __name__ == "__main__": t.setDaemon(True) t.start() + # PHP 502错误检查线程 p = threading.Thread(target=check502Task) if sys.version_info.major == 3 and sys.version_info.minor >= 10: p.daemon = True else: p.setDaemon(True) - p.start() + # OpenResty Auto Restart Start + oar = threading.Thread(target=openrestyAutoRestart) + if sys.version_info.major == 3 and sys.version_info.minor >= 10: + oar.daemon = True + else: + oar.setDaemon(True) + oar.start() + startTask()