diff --git a/plugins/openresty/check.sh b/plugins/openresty/check.sh new file mode 100755 index 000000000..8857db7ca --- /dev/null +++ b/plugins/openresty/check.sh @@ -0,0 +1,23 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH + +# OpenResty服务名称 +service_name="openresty" + +# 检查OpenResty是否正在运行 +if systemctl is-active --quiet "$service_name"; then + # 检查是否存在僵尸进程 + zombie_processes=$(ps -ef | grep -i openresty | grep -v grep | awk '{print $2}' | xargs ps -o state= -p 2>/dev/null | grep -c Z) + if [ "$zombie_processes" -gt 0 ]; then + echo "检测到OpenResty僵尸进程,正在重启服务..." + systemctl restart "$service_name" + echo "服务已重启" + else + echo "OpenResty运行正常" + fi +else + echo "OpenResty未运行,正在启动服务..." + systemctl start "$service_name" + echo "服务已启动" +fi diff --git a/plugins/openresty/index.html b/plugins/openresty/index.html index 086bec6de..ab2ec7ac1 100755 --- a/plugins/openresty/index.html +++ b/plugins/openresty/index.html @@ -8,6 +8,7 @@
负载状态
性能调整
错误日志
+其它功能
\ + \ + \ +
'; + $(".soft-man-con").html(con); +} + +function cronAddCheck(){ + orPost('cron_add_check', {}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + +function cronDelCheck(){ + orPost('cron_del_check', {}, function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 }); + }); +} + diff --git a/plugins/openresty/tool_task.py b/plugins/openresty/tool_task.py new file mode 100644 index 000000000..bc1cb3a85 --- /dev/null +++ b/plugins/openresty/tool_task.py @@ -0,0 +1,124 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import json + +web_dir = os.getcwd() + "/web" +if os.path.exists(web_dir): + sys.path.append(web_dir) + os.chdir(web_dir) + +import core.mw as mw +from utils.crontab import crontab as MwCrontab + + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'openresty' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getTaskConf(): + conf = getServerDir() + "/task_config.json" + return conf + + +def getConfigData(): + conf = getTaskConf() + if os.path.exists(conf): + return json.loads(mw.readFile(getTaskConf())) + return { + "task_id": -1, + "period": "minute-n", + "where1": "3", + "hour": "0", + "minute": "0", + } + + +def createBgTask(): + removeBgTask() + createBgTaskByName(getPluginName()) + + +def createBgTaskByName(name): + args = getConfigData() + _name = "[OpenResty]检查任务" + res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find() + if res: + return True + + if "task_id" in args and args["task_id"] > 0: + res = mw.M("crontab").field("id, name").where( + "id=?", (args["task_id"],)).find() + if res and res["id"] == args["task_id"]: + print("计划任务已经存在!") + return True + + mw_dir = mw.getPanelDir() + cmd = ''' +mw_dir=%s +rname=%s +plugin_path=%s +script_path=%s +''' % (mw_dir, name, getServerDir(), getPluginDir()) + cmd += 'echo "python3 $script_path/check.sh"' + "\n" + cmd += 'cd $mw_dir && bash $script_path/check.sh' + "\n" + + params = { + 'name': _name, + 'type': args['period'], + 'week': "", + 'where1': args['where1'], + 'hour': args['hour'], + 'minute': args['minute'], + 'save': "", + 'backup_to': "", + 'stype': "toShell", + 'sname': '', + 'sbody': cmd, + 'url_address': '', + } + + task_id = MwCrontab.instance().add(params) + if task_id > 0: + args["task_id"] = task_id + args["name"] = name + mw.writeFile(getTaskConf(), json.dumps(args)) + + +def removeBgTask(): + cfg = getConfigData() + if "task_id" in cfg and cfg["task_id"] > 0: + res = mw.M("crontab").field("id, name").where( + "id=?", (cfg["task_id"],)).find() + if res and res["id"] == cfg["task_id"]: + data = MwCrontab.instance().delete(cfg["task_id"]) + if data["status"]: + cfg["task_id"] = -1 + mw.writeFile(getTaskConf(), json.dumps(cfg)) + return True + return False + + +if __name__ == "__main__": + if len(sys.argv) > 1: + action = sys.argv[1] + if action == "remove": + removeBgTask() + elif action == "add": + createBgTask()