From 544a37a46da53c138fd30f5ea4f2ece0d0a21748 Mon Sep 17 00:00:00 2001 From: midoks Date: Thu, 16 Jun 2022 23:24:09 +0800 Subject: [PATCH] #31 --- plugins/supervisor/index.py | 53 +++++++++++++++++-- plugins/supervisor/js/supervisor.js | 81 ++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/plugins/supervisor/index.py b/plugins/supervisor/index.py index 1ec826843..fc6e8e277 100755 --- a/plugins/supervisor/index.py +++ b/plugins/supervisor/index.py @@ -271,7 +271,7 @@ def getSupList(): return mw.getJson(data) -def getUserList(): +def getUserListData(): user = getServerDir() + "/user.txt" if not os.path.isfile(user): os.system(r"touch {}".format(user)) @@ -291,6 +291,11 @@ def getUserList(): if user in special: continue user_list.append(user) + return user_list + + +def getUserList(): + user_list = getUserListData() return mw.getJson(user_list) @@ -366,10 +371,47 @@ def delJob(): def updateJob(): args = getArgs() - data = checkArgs(args, ['name']) + data = checkArgs(args, ["name", 'user', 'numprocs', 'priority']) if not data[0]: return data[1] + user = args['user'] + numprocs = args['numprocs'] + priority = args['priority'] name = args['name'] + programFile = getServerDir() + "/conf.d/" + name + ".ini" + + with open(programFile, "r") as fr: + infos = fr.readlines() + + mess = {} + infos = [] + for line in infos: + if "command=" in line.strip(): + mess["command"] = line.strip().split('=')[1] + if "path=" in line.strip(): + mess["path"] = line.strip().split('=')[1] + + log_dir = getServerDir() + '/log/' + + w_body = "" + w_body += "[program:" + name + "]" + "\n" + w_body += "command=" + mess["command"] + "\n" + w_body += "directory=" + mess["path"] + "\n" + w_body += "autorestart=true" + "\n" + w_body += "startsecs=3" + "\n" + w_body += "startretries=3" + "\n" + w_body += "stdout_logfile=" + log_dir + name + ".out.log" + "\n" + w_body += "stderr_logfile=" + log_dir + name + ".err.log" + "\n" + w_body += "stdout_logfile_maxbytes=2MB" + "\n" + w_body += "stderr_logfile_maxbytes=2MB" + "\n" + w_body += "user=" + user + "\n" + w_body += "priority=999" + "\n" + w_body += "numprocs={0}".format(numprocs) + "\n" + w_body += "process_name=%(program_name)s_%(process_num)02d" + + mw.writeFile(programFile, w_body) + + return mw.returnJson(True, '修改守护进程成功!') def getJobInfo(): @@ -379,10 +421,13 @@ def getJobInfo(): return data[1] name = args['name'] + mess = {} + infos = [] + info = {} program = getServerDir() + "/conf.d/" + name + ".ini" with open(program, "r") as fr: infos = fr.readlines() - + mess = {} for line in infos: if "user=" in line.strip(): mess["user"] = line.strip().split('=')[1] @@ -390,7 +435,7 @@ def getJobInfo(): mess["numprocs"] = line.strip().split('=')[1] if "priority=" in line.strip(): mess["priority"] = line.strip().split('=')[1] - userlist = getUserList() + userlist = getUserListData() info["userlist"] = userlist info["daemoninfo"] = mess return mw.getJson(info) diff --git a/plugins/supervisor/js/supervisor.js b/plugins/supervisor/js/supervisor.js index 707a05fc7..21449326e 100755 --- a/plugins/supervisor/js/supervisor.js +++ b/plugins/supervisor/js/supervisor.js @@ -107,7 +107,86 @@ function supList(page, search){ function updateJob(name){ + myPost('get_job_info',{'name':name},function(data){ + var rdata = $.parseJSON(data.data); + // console.log(rdata); + var defaultPath = $("#defaultPath").html(); + var ulist = "
启动用户
"; + layer.open({ + type: 1, + area: '500px', + title: '修改守护进程', + closeBtn: 2, + shift: 0, + shadeClose: false, + btn: ['确定', '取消'], + content: "
\ +
\ + 名称\ +
\ + \ +
\ +
\ + "+ulist+"\ +
\ + 进程数量\ +
\ + \ +
\ +
\ +
\ + 启动优先级\ +
\ + \ +
\ +
\ +
", + yes: function(index, layero){ + // console.log(index,layero); + + var options = ['name','user','numprocs','priority']; + var opval = {}; + for(var i in options){ + opval[options[i]] = $('[name="'+ options[i] +'"]').val(); + if(opval[options[i]] == ''){ + if(options[i] == 'user'){ + layer.msg('启动用户不能为空'); + return false; + }else if(options[i] == 'priority'){ + layer.msg('启动优先级不能为空'); + return false; + }else if(options[i] == 'numprocs'){ + layer.msg('进程数量不能为空!'); + return false; + } + } + } + + var numprocs = $('[name=numprocs]').val(); + if (!(/(^[1-9]\d*$)/.test(numprocs))) { + layer.msg('进程数量请输入正整数') + return false; +   } + + myPost("update_job", opval, function(data){ + rdata = $.parseJSON(data.data); + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + rdata.status ? layer.close(index):''; + supList(1,10); + }) + return; + } + }); + }); } @@ -136,7 +215,7 @@ function supAdd() { var defaultPath = $("#defaultPath").html(); var ulist = "
启动用户