mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:19:26 +08:00
up
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<div class="bt-form">
|
||||
<div class="bt-w-main">
|
||||
<div class='plugin_version'></div>
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('nezha');">面板服务</p>
|
||||
<p onclick="pluginInitD('nezha');">面板自启动</p>
|
||||
<p class="bgw" onclick="pluginService('nezha');">AGENT服务</p>
|
||||
<p onclick="pluginInitD('nezha');">AGENT自启动</p>
|
||||
<p onclick="pluginService('nezha', $('.plugin_version').attr('version'), 'agent');">AGENT服务</p>
|
||||
<p onclick="pluginInitD('nezha', $('.plugin_version').attr('version'), 'agent');">AGENT自启动</p>
|
||||
<p onclick="pluginConfig('nezha',null, 'conf');">面板配置文件</p>
|
||||
</div>
|
||||
<div class="bt-w-con pd15">
|
||||
@@ -16,7 +17,7 @@
|
||||
<script type="text/javascript">
|
||||
resetPluginWinHeight(530);
|
||||
$.getScript( "/plugins/file?name=nezha&f=js/nezha.js", function(){
|
||||
mail.init();
|
||||
nezha.init();
|
||||
pluginService('nezha');
|
||||
});
|
||||
</script>
|
||||
@@ -98,6 +98,13 @@ class App:
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
def status_agent(self):
|
||||
cmd = "ps -ef | grep nezha-agent | grep -v grep | grep -v python | awk '{print $2}'"
|
||||
data = mw.execShell(cmd)
|
||||
if data[0] == '':
|
||||
return 'stop'
|
||||
return 'start'
|
||||
|
||||
def contentReplace(self, content):
|
||||
|
||||
service_path = mw.getServerDir()
|
||||
@@ -139,6 +146,31 @@ class App:
|
||||
|
||||
return file_bin
|
||||
|
||||
def initDAgent(self):
|
||||
initD_path = self.getServerDir() + '/init.d'
|
||||
if not os.path.exists(initD_path):
|
||||
os.mkdir(initD_path)
|
||||
|
||||
file_agent_bin = initD_path + '/nezha-agent'
|
||||
if not os.path.exists(file_agent_bin):
|
||||
content = mw.readFile(file_tpl)
|
||||
content = self.contentReplace(content)
|
||||
mw.writeFile(file_agent_bin, content)
|
||||
mw.execShell('chmod +x ' + file_agent_bin)
|
||||
|
||||
# systemd
|
||||
sysDir = mw.systemdCfgDir()
|
||||
sysService = sysDir + '/nezha-agent.service'
|
||||
sysServiceTpl = self.getPluginDir() + '/init.d/nezha-agent.service.tpl'
|
||||
if os.path.exists(sysDir) and not os.path.exists(sysService):
|
||||
service_path = mw.getServerDir()
|
||||
content = mw.readFile(sysServiceTpl)
|
||||
content = self.contentReplace(content)
|
||||
mw.writeFile(sysService, content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
return file_agent_bin
|
||||
|
||||
def imOp(self, method):
|
||||
file = self.initDreplace()
|
||||
|
||||
@@ -166,6 +198,33 @@ class App:
|
||||
def reload(self):
|
||||
return self.imOp('reload')
|
||||
|
||||
def agOp(self, method):
|
||||
file = self.initDAgent()
|
||||
|
||||
if not mw.isAppleSystem():
|
||||
cmd = 'systemctl {} {}'.format(method, 'nezha-agent')
|
||||
data = mw.execShell(cmd)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
data = mw.execShell(file + ' ' + method)
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return data[0]
|
||||
|
||||
def start_agent(self):
|
||||
return self.agOp('start')
|
||||
|
||||
def stop_agent(self):
|
||||
return self.agOp('stop')
|
||||
|
||||
def restart_agent(self):
|
||||
return self.agOp('restart')
|
||||
|
||||
def reload_agent(self):
|
||||
return self.agentOp('reload')
|
||||
|
||||
def initd_status(self):
|
||||
cmd = 'systemctl status nezha | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(cmd)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"author": "midoks",
|
||||
"date": "2023-06-26",
|
||||
"home": "https://github.com/midoks/nezha",
|
||||
"doc1": "https://nezha.wiki/",
|
||||
"type": 0,
|
||||
"pid": "5"
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
# chkconfig: 2345 55 25
|
||||
# description: Nezha Service
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: Nezha
|
||||
# Required-Start: $all
|
||||
# Required-Stop: $all
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: starts Nezha
|
||||
# Description: starts the Nezha
|
||||
### END INIT INFO
|
||||
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||
|
||||
if [ -f /etc/init.d/functions ];then
|
||||
. /etc/init.d/functions
|
||||
fi
|
||||
|
||||
if [ -f /etc/rc.d/init.d/functions ];then
|
||||
. /etc/rc.d/init.d/functions
|
||||
fi
|
||||
|
||||
SERVICENAME=nezha-agnet
|
||||
LOG_PATH={$SERVER_PATH}/${SERVICENAME}/logs
|
||||
APP_PATH={$SERVER_PATH}/${SERVICENAME}/agent
|
||||
|
||||
|
||||
app_start(){
|
||||
isStart=`ps -ef|grep "${SERVICENAME} web" | grep -v grep | grep -v python | grep -v "/bin/bash" | awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "Starting ${SERVICENAME}... \c"
|
||||
cd $APP_PATH && exec nohup ${APP_PATH}/${SERVICENAME} web >> ${LOG_PATH}/${SERVICENAME}.log 2>&1 &
|
||||
isStart=""
|
||||
while [[ "$isStart" == "" ]];
|
||||
do
|
||||
echo -e ".\c"
|
||||
sleep 0.5
|
||||
isStart=$(ps -ef|grep "${SERVICENAME} web" |grep -v grep | grep -v python | grep -v "/bin/bash" | awk '{print $2}')
|
||||
let n+=1
|
||||
if [ $n -gt 15 ];then
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "\033[31mError: ${SERVICENAME} service startup failed.\033[0m"
|
||||
return;
|
||||
fi
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
else
|
||||
echo "Starting ${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
app_stop(){
|
||||
pids=`ps -ef | grep "${SERVICENAME} web" | grep -v grep | grep -v python | grep -v "/bin/bash" |awk '{print $2}'`
|
||||
arr=($pids)
|
||||
echo -e "Stopping ${SERVICENAME}... \c"
|
||||
for p in ${arr[@]}
|
||||
do
|
||||
# echo "$p"
|
||||
kill -9 $p
|
||||
done
|
||||
echo -e "\033[32mdone\033[0m"
|
||||
}
|
||||
|
||||
app_status(){
|
||||
isStart=`ps -ef | grep "${SERVICENAME} web" | grep -v grep | grep -v python | grep -v "/bin/bash" | awk '{print $2}'`
|
||||
if [ "$isStart" == '' ];then
|
||||
echo -e "${SERVICENAME} not running"
|
||||
else
|
||||
echo -e "${SERVICENAME}(pid $(echo $isStart)) already running"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
'start') app_start;;
|
||||
'stop') app_stop;;
|
||||
'status') app_status;;
|
||||
'reload')
|
||||
app_stop
|
||||
app_start;;
|
||||
'restart')
|
||||
app_stop
|
||||
app_start;;
|
||||
esac
|
||||
+31
-13
@@ -1924,14 +1924,19 @@ function utf8to16(str) {
|
||||
}
|
||||
|
||||
|
||||
function pluginService(_name, version){
|
||||
var data = {name:_name, func:'status'}
|
||||
function pluginService(_name, version, _suffix_name=''){
|
||||
|
||||
var default_name = 'status';
|
||||
if ( _suffix_name != '' ){
|
||||
default_name = 'status_'+_suffix_name;
|
||||
}
|
||||
|
||||
var data = {name:_name, func:default_name};
|
||||
if ( typeof(version) != 'undefined' ){
|
||||
data['version'] = version;
|
||||
} else {
|
||||
version = '';
|
||||
}
|
||||
// console.log(version);
|
||||
|
||||
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
|
||||
$.post('/plugins/run', data, function(data) {
|
||||
@@ -1941,27 +1946,39 @@ function pluginService(_name, version){
|
||||
return;
|
||||
}
|
||||
if (data.data == 'start'){
|
||||
pluginSetService(_name, true, version);
|
||||
pluginSetService(_name, true, version, _suffix_name);
|
||||
} else {
|
||||
pluginSetService(_name, false, version);
|
||||
pluginSetService(_name, false, version, _suffix_name);
|
||||
}
|
||||
},'json');
|
||||
}
|
||||
|
||||
function pluginSetService(_name ,status, version){
|
||||
function pluginSetService(_name ,status, version, _suffix_name=''){
|
||||
|
||||
var default_name = 'status';
|
||||
var restart_name = 'restart';
|
||||
var reload_name = 'reload';
|
||||
var status_ss = (status?'stop':'start');
|
||||
if ( _suffix_name != '' ){
|
||||
default_name = 'status_'+_suffix_name;
|
||||
restart_name = 'restart_'+_suffix_name;
|
||||
reload_name = 'reload_'+_suffix_name;
|
||||
status_ss = status_ss+'_'+_suffix_name;
|
||||
}
|
||||
|
||||
var serviceCon ='<p class="status">当前状态:<span>'+(status ? '开启' : '关闭' )+
|
||||
'</span><span style="color: '+
|
||||
(status?'#20a53a;':'red;')+
|
||||
' margin-left: 3px;" class="glyphicon ' + (status?'glyphicon glyphicon-play':'glyphicon-pause')+'"></span></p><div class="sfm-opt">\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\''+(status?'stop':'start')+'\',\''+version+'\')">'+(status?'停止':'启动')+'</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\'restart\',\''+version+'\')">重启</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\'reload\',\''+version+'\')">重载配置</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\''+status_ss+'\',\''+version+'\',\''+_suffix_name+'\')">'+(status?'停止':'启动')+'</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\''+restart_name+'\',\''+version+'\',\''+_suffix_name+'\')">重启</button>\
|
||||
<button class="btn btn-default btn-sm" onclick="pluginOpService(\''+_name+'\',\''+reload_name+'\',\''+version+'\',\''+_suffix_name+'\')">重载配置</button>\
|
||||
</div>';
|
||||
$(".soft-man-con").html(serviceCon);
|
||||
}
|
||||
|
||||
|
||||
function pluginOpService(a, b, v) {
|
||||
function pluginOpService(a, b, v, _suffix_name='') {
|
||||
|
||||
var c = "name=" + a + "&func=" + b;
|
||||
if(v != ''){
|
||||
@@ -1969,6 +1986,8 @@ function pluginOpService(a, b, v) {
|
||||
}
|
||||
|
||||
var d = "";
|
||||
|
||||
b = b.split('_')[0];
|
||||
switch(b) {
|
||||
case "stop":d = '停止';break;
|
||||
case "start":d = '启动';break;
|
||||
@@ -1980,15 +1999,14 @@ function pluginOpService(a, b, v) {
|
||||
$.post("/plugins/run", c, function(g) {
|
||||
layer.close(e);
|
||||
|
||||
|
||||
var f = g.data == 'ok' ? msgTpl('{1}{2}服务已{3}',[a,v,d]) : msgTpl('{1}{2}服务{3}失败!',[a,v,d]);
|
||||
layer.msg(f, {icon: g.data == 'ok' ? 1 : 2});
|
||||
|
||||
if( b != "reload" && g.data == 'ok' ) {
|
||||
if ( b == 'start' ) {
|
||||
pluginSetService(a, true, v);
|
||||
pluginSetService(a, true, v, _suffix_name);
|
||||
} else if ( b == 'stop' ){
|
||||
pluginSetService(a, false, v);
|
||||
pluginSetService(a, false, v, _suffix_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user