mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:19:26 +08:00
This commit is contained in:
@@ -73,6 +73,7 @@ def initInitD():
|
||||
# 加入自启动
|
||||
mw.execShell('chkconfig --add mw')
|
||||
mw.execShell('systemctl enable mw')
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
|
||||
def initUserInfo():
|
||||
|
||||
@@ -52,7 +52,7 @@ silent=false ; no logs to stdout if true; default false
|
||||
minfds=1024 ; min. avail startup file descriptors; default 1024
|
||||
minprocs=200 ; min. avail process descriptors;default 200
|
||||
;umask=022 ; process file creation umask; default 022
|
||||
;user=supervisord ; setuid to this UNIX account at startup; recommended if root
|
||||
user={$OS_USER} ; setuid to this UNIX account at startup; recommended if root
|
||||
;identifier=supervisor ; supervisord identifier, default is 'supervisor'
|
||||
;directory=/tmp ; default is not to cd during start
|
||||
;nocleanup=true ; don't clean up tempfiles at start; default false
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<div class="bt-w-main">
|
||||
<div class="bt-w-menu">
|
||||
<p class="bgw" onclick="pluginService('supervisor');">服务</p>
|
||||
<p onclick="pluginInitD('supervisor');">自启动</p>
|
||||
<p onclick="supList();">进程管理</p>
|
||||
<p onclick="pluginConfig('supervisor');">主配置</p>
|
||||
<p onclick="pluginLogs('supervisor','','run_log', 10);">主日志</p>
|
||||
|
||||
+70
-46
@@ -26,12 +26,6 @@ def getServerDir():
|
||||
return mw.getServerDir() + '/' + getPluginName()
|
||||
|
||||
|
||||
def getInitDFile():
|
||||
if app_debug:
|
||||
return '/tmp/' + getPluginName()
|
||||
return '/etc/init.d/' + getPluginName()
|
||||
|
||||
|
||||
def getConf():
|
||||
path = getServerDir() + "/supervisor.conf"
|
||||
return path
|
||||
@@ -76,7 +70,6 @@ def checkArgs(data, ck=[]):
|
||||
|
||||
|
||||
def status():
|
||||
|
||||
data = mw.execShell(
|
||||
"ps -ef|grep supervisor | grep -v grep | grep -v index.py | awk '{print $2}'")
|
||||
if data[0] == '':
|
||||
@@ -86,33 +79,49 @@ def status():
|
||||
|
||||
def initDreplace():
|
||||
|
||||
# initD_path = getServerDir() + '/init.d'
|
||||
# if not os.path.exists(initD_path):
|
||||
# os.mkdir(initD_path)
|
||||
# file_bin = initD_path + '/' + getPluginName()
|
||||
confD = etServerDir() + "/conf.d"
|
||||
conf = etServerDir() + "//supervisor.conf"
|
||||
systemDir = '/lib/systemd/system'
|
||||
systemService = systemDir + '/supervisor.service'
|
||||
systemServiceTpl = getPluginDir() + '/init.d/supervisor.service'
|
||||
|
||||
# file_tpl = getInitDTpl()
|
||||
# initd replace
|
||||
# content = mw.readFile(file_tpl)
|
||||
# content = content.replace('{$SERVER_PATH}', service_path)
|
||||
# mw.writeFile(file_bin, content)
|
||||
# mw.execShell('chmod +x ' + file_bin)
|
||||
|
||||
if not os.path.exists(getServerDir() + "/conf.d"):
|
||||
os.mkdir(getServerDir() + "/conf.d")
|
||||
|
||||
if not os.path.exists(getServerDir() + '/supervisor.conf'):
|
||||
# config replace
|
||||
service_path = os.path.dirname(os.getcwd())
|
||||
|
||||
if not os.path.exists(confD):
|
||||
os.mkdir(confD)
|
||||
|
||||
if not os.path.exists(conf):
|
||||
# config replace
|
||||
user = 'root'
|
||||
if mw.isAppleSystem():
|
||||
cmd = "who | sed -n '2, 1p' |awk '{print $1}'"
|
||||
user = mw.execShell(cmd)[0].strip()
|
||||
|
||||
conf_content = mw.readFile(getConfTpl())
|
||||
conf_content = conf_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(getServerDir() + '/supervisor.conf', conf_content)
|
||||
conf_content = conf_content.replace('{$OS_USER}', user)
|
||||
mw.writeFile(conf, conf_content)
|
||||
|
||||
if os.path.exists(systemDir) and not os.path.exists(systemService):
|
||||
se_content = mw.readFile(systemServiceTpl)
|
||||
se_content = conf_content.replace('{$SERVER_PATH}', service_path)
|
||||
mw.writeFile(systemService, se_content)
|
||||
mw.execShell('systemctl daemon-reload')
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def start():
|
||||
initDreplace()
|
||||
|
||||
systemDir = '/lib/systemd/system'
|
||||
systemService = systemDir + '/supervisor.service'
|
||||
if os.path.exists(systemService):
|
||||
data = mw.execShell('systemctl start supervisor')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
cmd = 'supervisord -c ' + getServerDir() + '/supervisor.conf'
|
||||
# print(cmd)
|
||||
data = mw.execShell(cmd)
|
||||
@@ -124,7 +133,15 @@ def start():
|
||||
|
||||
def stop():
|
||||
initDreplace()
|
||||
data = mw.execShell('supervisorctl shutdown')
|
||||
|
||||
systemDir = '/lib/systemd/system'
|
||||
systemService = systemDir + '/supervisor.service'
|
||||
if os.path.exists(systemService):
|
||||
data = mw.execShell('systemctl stop supervisor')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
mw.execShell(
|
||||
"ps -ef|grep supervisor | grep -v grep | grep -v index.py | awk '{print $2}'|xargs kill")
|
||||
if data[1] == '':
|
||||
@@ -133,47 +150,51 @@ def stop():
|
||||
|
||||
|
||||
def restart():
|
||||
systemDir = '/lib/systemd/system'
|
||||
systemService = systemDir + '/supervisor.service'
|
||||
if os.path.exists(systemService):
|
||||
data = mw.execShell('systemctl restart supervisor')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
mw.execShell(
|
||||
"ps -ef|grep supervisor | grep -v grep | grep -v index.py | awk '{print $2}'|xargs kill")
|
||||
|
||||
return start()
|
||||
initDreplace()
|
||||
data = mw.execShell('supervisorctl reload')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
|
||||
def reload():
|
||||
initDreplace()
|
||||
data = mw.execShell('supervisorctl reload')
|
||||
|
||||
systemDir = '/lib/systemd/system'
|
||||
systemService = systemDir + '/supervisor.service'
|
||||
if os.path.exists(systemService):
|
||||
data = mw.execShell('systemctl reload supervisor')
|
||||
if data[1] == '':
|
||||
return 'ok'
|
||||
return 'fail'
|
||||
|
||||
mw.execShell(
|
||||
"ps -ef|grep supervisor | grep -v grep | grep -v index.py | awk '{print $2}'|xargs kill")
|
||||
return start()
|
||||
|
||||
|
||||
def initdStatus():
|
||||
if not app_debug:
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
initd_bin = getInitDFile()
|
||||
if os.path.exists(initd_bin):
|
||||
return 'ok'
|
||||
|
||||
shell_cmd = 'systemctl status supervisor | grep loaded | grep "enabled;"'
|
||||
data = mw.execShell(shell_cmd)
|
||||
if data[0] == '':
|
||||
return 'fail'
|
||||
return 'ok'
|
||||
|
||||
|
||||
def initdInstall():
|
||||
import shutil
|
||||
if not app_debug:
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
source_bin = initDreplace()
|
||||
initd_bin = getInitDFile()
|
||||
shutil.copyfile(source_bin, initd_bin)
|
||||
mw.execShell('chmod +x ' + initd_bin)
|
||||
mw.execShell('chkconfig --add ' + getPluginName())
|
||||
mw.execShell('systemctl enable supervisor')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -182,9 +203,7 @@ def initdUinstall():
|
||||
if mw.isAppleSystem():
|
||||
return "Apple Computer does not support"
|
||||
|
||||
mw.execShell('chkconfig --del ' + getPluginName())
|
||||
initd_bin = getInitDFile()
|
||||
os.remove(initd_bin)
|
||||
mw.execShell('systemctl diable supervisor')
|
||||
return 'ok'
|
||||
|
||||
|
||||
@@ -259,6 +278,11 @@ def getUserListData():
|
||||
if user in special:
|
||||
continue
|
||||
user_list.append(user)
|
||||
|
||||
if mw.isAppleSystem():
|
||||
cmd = "who | sed -n '2, 1p' |awk '{print $1}'"
|
||||
user = mw.execShell(cmd)[0].strip()
|
||||
user_list.append(user)
|
||||
return user_list
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=supervisor server daemon
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
ExecStart=supervisord -c {$SERVER_PATH}/supervisor/supervisor.conf
|
||||
ExecStop=supervisorctl -c {$SERVER_PATH}/supervisor/supervisor.conf $OPTIONS shutdown
|
||||
ExecReload=supervisorctl -c {$SERVER_PATH}/supervisor/supervisor.conf $OPTIONS reload
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -51,13 +51,18 @@ Install_app()
|
||||
fi
|
||||
|
||||
echo "${VERSION}" > $serverPath/supervisor/version.pl
|
||||
echo '安装完成' > $install_tmp
|
||||
echo '安装完成[supervisor]' > $install_tmp
|
||||
}
|
||||
|
||||
Uninstall_app()
|
||||
{
|
||||
rm -rf $serverPath/supervisor
|
||||
echo "Uninstall_redis" > $install_tmp
|
||||
|
||||
if [ -f /lib/systemd/system/supervisor.service ];then
|
||||
rm -rf /lib/systemd/system/supervisor.service
|
||||
fi
|
||||
|
||||
echo "卸载完成[supervisor]" > $install_tmp
|
||||
}
|
||||
|
||||
action=$1
|
||||
|
||||
Reference in New Issue
Block a user