diff --git a/plugins/nezha/index.py b/plugins/nezha/index.py index 9bf1763fc..c85f5851b 100755 --- a/plugins/nezha/index.py +++ b/plugins/nezha/index.py @@ -133,7 +133,7 @@ class App: if os.path.exists(systemDir) and not os.path.exists(systemService): service_path = mw.getServerDir() se_content = mw.readFile(systemServiceTpl) - se_content = se_content.replace('{$SERVER_PATH}', service_path) + se_content = self.contentReplace(se_content) mw.writeFile(systemService, se_content) mw.execShell('systemctl daemon-reload') @@ -149,7 +149,7 @@ class App: return 'ok' return 'fail' - data = mw.execShell(self.__SR + file + ' ' + method) + data = mw.execShell(file + ' ' + method) if data[1] == '': return 'ok' return data[0] diff --git a/plugins/nezha/init.d/nezha.tpl b/plugins/nezha/init.d/nezha.tpl new file mode 100644 index 000000000..4f1e20404 --- /dev/null +++ b/plugins/nezha/init.d/nezha.tpl @@ -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 +LOG_PATH={$SERVER_PATH}/${SERVICENAME}/logs +APP_PATH={$SERVER_PATH}/${SERVICENAME}/dashboard + + +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 \ No newline at end of file