mirror of https://github.com/midoks/mdserver-web
parent
e43970652e
commit
a958bb977c
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,20 @@ |
|||||||
|
<div class="bt-form"> |
||||||
|
<div class="bt-w-main"> |
||||||
|
<div class="bt-w-menu"> |
||||||
|
<p class="bgw" onclick="pluginService('jenkins');">服务</p> |
||||||
|
<p onclick="pluginInitD('jenkins');">自启动</p> |
||||||
|
<p onclick="pluginLogs('jenkins','','run_log');">日志</p> |
||||||
|
<p onclick="pRead()">说明</p> |
||||||
|
</div> |
||||||
|
<div class="bt-w-con pd15"> |
||||||
|
<div class="soft-man-con"></div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<script type="text/javascript"> |
||||||
|
resetPluginWinWidth(700); |
||||||
|
$.getScript( "/plugins/file?name=jenkins&f=js/jenkins.js", function() { |
||||||
|
pluginService('walle'); |
||||||
|
}); |
||||||
|
</script> |
@ -0,0 +1,211 @@ |
|||||||
|
# coding: utf-8 |
||||||
|
|
||||||
|
import time |
||||||
|
import random |
||||||
|
import os |
||||||
|
import json |
||||||
|
import re |
||||||
|
import sys |
||||||
|
import subprocess |
||||||
|
|
||||||
|
sys.path.append(os.getcwd() + "/class/core") |
||||||
|
import public |
||||||
|
|
||||||
|
app_debug = False |
||||||
|
if public.isAppleSystem(): |
||||||
|
app_debug = True |
||||||
|
|
||||||
|
|
||||||
|
def getPluginName(): |
||||||
|
return 'jenkins' |
||||||
|
|
||||||
|
|
||||||
|
def getPluginDir(): |
||||||
|
return public.getPluginDir() + '/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getServerDir(): |
||||||
|
return public.getServerDir() + '/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getInitDFile(): |
||||||
|
if app_debug: |
||||||
|
return '/tmp/' + getPluginName() |
||||||
|
return '/etc/init.d/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getInitDTpl(): |
||||||
|
return getPluginDir() + "/init.d/" + getPluginName() + ".tpl" |
||||||
|
|
||||||
|
|
||||||
|
def getLog(): |
||||||
|
return getServerDir() + "/code/logs/error.log" |
||||||
|
|
||||||
|
|
||||||
|
def getArgs(): |
||||||
|
args = sys.argv[2:] |
||||||
|
tmp = {} |
||||||
|
args_len = len(args) |
||||||
|
|
||||||
|
if args_len == 1: |
||||||
|
t = args[0].strip('{').strip('}') |
||||||
|
t = t.split(':') |
||||||
|
tmp[t[0]] = t[1] |
||||||
|
elif args_len > 1: |
||||||
|
for i in range(len(args)): |
||||||
|
t = args[i].split(':') |
||||||
|
tmp[t[0]] = t[1] |
||||||
|
|
||||||
|
return tmp |
||||||
|
|
||||||
|
|
||||||
|
def checkArgs(data, ck=[]): |
||||||
|
for i in range(len(ck)): |
||||||
|
if not ck[i] in data: |
||||||
|
return (False, public.returnJson(False, '参数:(' + ck[i] + ')没有!')) |
||||||
|
return (True, public.returnJson(True, 'ok')) |
||||||
|
|
||||||
|
|
||||||
|
def status(): |
||||||
|
pn = getPluginName() |
||||||
|
cmd = "ps -ef|grep 'waller.py' | grep -v grep | awk '{print $2}'" |
||||||
|
data = public.execShell(cmd) |
||||||
|
if data[0] == '': |
||||||
|
return 'stop' |
||||||
|
return 'start' |
||||||
|
|
||||||
|
|
||||||
|
def initDreplace(): |
||||||
|
|
||||||
|
file_tpl = getInitDTpl() |
||||||
|
service_path = os.path.dirname(os.getcwd()) |
||||||
|
|
||||||
|
initD_path = getServerDir() + '/init.d' |
||||||
|
if not os.path.exists(initD_path): |
||||||
|
os.mkdir(initD_path) |
||||||
|
|
||||||
|
file_bin = initD_path + '/' + getPluginName() |
||||||
|
if not os.path.exists(file_bin): |
||||||
|
content = public.readFile(file_tpl) |
||||||
|
content = content.replace('{$SERVER_PATH}', service_path) |
||||||
|
public.writeFile(file_bin, content) |
||||||
|
public.execShell('chmod +x ' + file_bin) |
||||||
|
|
||||||
|
return file_bin |
||||||
|
|
||||||
|
|
||||||
|
def runShell(shell): |
||||||
|
data = public.execShell(shell) |
||||||
|
return data |
||||||
|
|
||||||
|
|
||||||
|
def start(): |
||||||
|
file = initDreplace() |
||||||
|
cmd = file + ' start' |
||||||
|
data = subprocess.Popen( |
||||||
|
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def stop(): |
||||||
|
file = initDreplace() |
||||||
|
data = runShell(file + ' stop') |
||||||
|
if data[1] == '': |
||||||
|
return 'ok' |
||||||
|
return 'fail' |
||||||
|
|
||||||
|
|
||||||
|
def restart(): |
||||||
|
file = initDreplace() |
||||||
|
cmd = file + ' restart' |
||||||
|
data = subprocess.Popen( |
||||||
|
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def reload(): |
||||||
|
file = initDreplace() |
||||||
|
data = runShell(file + ' reload') |
||||||
|
|
||||||
|
solr_log = getServerDir() + "/code/logs/walle.log" |
||||||
|
public.writeFile(solr_log, "") |
||||||
|
|
||||||
|
if data[1] == '': |
||||||
|
return 'ok' |
||||||
|
return 'fail' |
||||||
|
|
||||||
|
|
||||||
|
def initdStatus(): |
||||||
|
initd_bin = getInitDFile() |
||||||
|
if os.path.exists(initd_bin): |
||||||
|
return 'ok' |
||||||
|
return 'fail' |
||||||
|
|
||||||
|
|
||||||
|
def initdInstall(): |
||||||
|
import shutil |
||||||
|
|
||||||
|
source_bin = initDreplace() |
||||||
|
initd_bin = getInitDFile() |
||||||
|
shutil.copyfile(source_bin, initd_bin) |
||||||
|
public.execShell('chmod +x ' + initd_bin) |
||||||
|
|
||||||
|
if not app_debug: |
||||||
|
public.execShell('chkconfig --add ' + getPluginName()) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def initdUinstall(): |
||||||
|
if not app_debug: |
||||||
|
public.execShell('chkconfig --del ' + getPluginName()) |
||||||
|
|
||||||
|
initd_bin = getInitDFile() |
||||||
|
|
||||||
|
if os.path.exists(initd_bin): |
||||||
|
os.remove(initd_bin) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def prodConf(): |
||||||
|
return getServerDir() + "/code/walle/config/settings_prod.py" |
||||||
|
|
||||||
|
|
||||||
|
def initEnv(): |
||||||
|
cmd = "cd " + getServerDir() + "/code" + " && sh admin.sh init" |
||||||
|
data = public.execShell(cmd) |
||||||
|
return "shell:<br>" + data[0] + "<br>" + " error:<br>" + data[1] |
||||||
|
|
||||||
|
|
||||||
|
def initData(): |
||||||
|
cmd = "cd " + getServerDir() + "/code" + " && sh admin.sh migration" |
||||||
|
data = public.execShell(cmd) |
||||||
|
return "shell:<br>" + data[0] + "<br>" + " error:<br>" + data[1] |
||||||
|
# rsyncdReceive |
||||||
|
if __name__ == "__main__": |
||||||
|
func = sys.argv[1] |
||||||
|
if func == 'status': |
||||||
|
print status() |
||||||
|
elif func == 'start': |
||||||
|
print start() |
||||||
|
elif func == 'stop': |
||||||
|
print stop() |
||||||
|
elif func == 'restart': |
||||||
|
print restart() |
||||||
|
elif func == 'reload': |
||||||
|
print reload() |
||||||
|
elif func == 'initd_status': |
||||||
|
print initdStatus() |
||||||
|
elif func == 'initd_install': |
||||||
|
print initdInstall() |
||||||
|
elif func == 'initd_uninstall': |
||||||
|
print initdUinstall() |
||||||
|
elif func == 'run_log': |
||||||
|
print getLog() |
||||||
|
elif func == 'prod_conf': |
||||||
|
print prodConf() |
||||||
|
elif func == 'init_env': |
||||||
|
print initEnv() |
||||||
|
elif func == 'init_data': |
||||||
|
print initData() |
||||||
|
else: |
||||||
|
print 'error' |
@ -0,0 +1,16 @@ |
|||||||
|
{ |
||||||
|
"id":13, |
||||||
|
"title":"jenkins", |
||||||
|
"tip":"soft", |
||||||
|
"name":"jenkins", |
||||||
|
"type":"扩展", |
||||||
|
"ps":"开源CI&CD软件领导者", |
||||||
|
"versions":"1.0", |
||||||
|
"shell":"install.sh", |
||||||
|
"checks":"server/jenkins", |
||||||
|
"path": "server/jenkins", |
||||||
|
"author":"midoks", |
||||||
|
"home":"https://jenkins.io/zh/", |
||||||
|
"date":"2019-12-06", |
||||||
|
"pid":"3" |
||||||
|
} |
@ -0,0 +1,114 @@ |
|||||||
|
#!/bin/bash |
||||||
|
# chkconfig: 2345 55 25 |
||||||
|
# description: Walle Service |
||||||
|
|
||||||
|
### BEGIN INIT INFO |
||||||
|
# Provides: bt |
||||||
|
# Required-Start: $all |
||||||
|
# Required-Stop: $all |
||||||
|
# Default-Start: 2 3 4 5 |
||||||
|
# Default-Stop: 0 1 6 |
||||||
|
# Short-Description: starts walle |
||||||
|
# Description: starts the walle |
||||||
|
### END INIT INFO |
||||||
|
|
||||||
|
|
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||||
|
|
||||||
|
app_path={$SERVER_PATH}/walle/code |
||||||
|
|
||||||
|
|
||||||
|
walle_start(){ |
||||||
|
isStart=`ps aux | grep 'waller.py'| grep -v grep | awk '{print $2}'` |
||||||
|
if [ "$isStart" == '' ];then |
||||||
|
echo -e "Starting walle... \c" |
||||||
|
cd $app_path && python waller.py >> $app_path/logs/walle.log 2>&1 & |
||||||
|
sleep 0.3 |
||||||
|
isStart=`ps aux | grep 'waller.py' | grep -v grep | awk '{print $2}'` |
||||||
|
sleep 0.2 |
||||||
|
if [ "$isStart" == '' ];then |
||||||
|
echo -e "\033[31mfailed\033[0m" |
||||||
|
echo '------------------------------------------------------' |
||||||
|
tail -n 20 $app_path/logs/walle.log |
||||||
|
echo '------------------------------------------------------' |
||||||
|
echo -e "\033[31mError: walle service startup failed.\033[0m" |
||||||
|
return |
||||||
|
fi |
||||||
|
echo -e "\033[32mdone\033[0m" |
||||||
|
else |
||||||
|
echo "Starting ... walle (pid $isStart) already running" |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
walle_stop() |
||||||
|
{ |
||||||
|
echo -e "Stopping walle... \c"; |
||||||
|
pids=$(ps aux | grep 'waller.py'|grep -v grep|awk '{print $2}') |
||||||
|
arr=($pids) |
||||||
|
|
||||||
|
for p in ${arr[@]} |
||||||
|
do |
||||||
|
kill -9 $p |
||||||
|
done |
||||||
|
echo -e "\033[32mdone\033[0m" |
||||||
|
|
||||||
|
echo -e "Stopping walle... \c"; |
||||||
|
arr=`ps aux | grep 'waller.py' | grep -v grep | awk '{print $2}'` |
||||||
|
for p in ${arr[@]} |
||||||
|
do |
||||||
|
kill -9 $p &>/dev/null |
||||||
|
done |
||||||
|
|
||||||
|
if [ -f $pidfile ];then |
||||||
|
rm -f $pidfile |
||||||
|
fi |
||||||
|
echo -e "\033[32mdone\033[0m" |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
walle_reload() |
||||||
|
{ |
||||||
|
isStart=$(ps aux | grep 'waller.py' | grep -v grep | awk '{print $2}') |
||||||
|
|
||||||
|
if [ "$isStart" != '' ];then |
||||||
|
echo -e "Reload walle... \c"; |
||||||
|
arr=`ps aux|grep 'waller.py' |grep -v grep|awk '{print $2}'` |
||||||
|
for p in ${arr[@]} |
||||||
|
do |
||||||
|
kill -9 $p |
||||||
|
done |
||||||
|
cd $app_path && nohup python waller.py >> $app_path/logs/walle.log 2>&1 & |
||||||
|
isStart=`ps aux | grep 'waller.py' | grep -v grep | awk '{print $2}'` |
||||||
|
if [ "$isStart" == '' ];then |
||||||
|
echo -e "\033[31mfailed\033[0m" |
||||||
|
echo '------------------------------------------------------' |
||||||
|
tail -n 20 $app_path/logs/walle.log |
||||||
|
echo '------------------------------------------------------' |
||||||
|
echo -e "\033[31mError: walle service startup failed.\033[0m" |
||||||
|
return |
||||||
|
fi |
||||||
|
echo -e "\033[32mdone\033[0m" |
||||||
|
else |
||||||
|
echo -e "\033[31m walle not running\033[0m" |
||||||
|
mw_start |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
error_logs() |
||||||
|
{ |
||||||
|
tail -n 100 ${app_path}/logs/walle.log |
||||||
|
} |
||||||
|
|
||||||
|
case "$1" in |
||||||
|
'start') walle_start;; |
||||||
|
'stop') walle_stop;; |
||||||
|
'reload') walle_reload;; |
||||||
|
'restart') |
||||||
|
walle_stop |
||||||
|
walle_start;; |
||||||
|
'logs') error_logs;; |
||||||
|
esac |
||||||
|
|
@ -0,0 +1,43 @@ |
|||||||
|
#!/bin/bash |
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||||
|
export PATH |
||||||
|
|
||||||
|
|
||||||
|
curPath=`pwd` |
||||||
|
rootPath=$(dirname "$curPath") |
||||||
|
rootPath=$(dirname "$rootPath") |
||||||
|
serverPath=$(dirname "$rootPath") |
||||||
|
install_tmp=${rootPath}/tmp/mw_install.pl |
||||||
|
sysName=`uname` |
||||||
|
|
||||||
|
Install_walle() |
||||||
|
{ |
||||||
|
echo '正在安装脚本文件...' > $install_tmp |
||||||
|
mkdir -p $serverPath/jenkins |
||||||
|
echo '1.0' > $serverPath/jenkins/version.pl |
||||||
|
|
||||||
|
|
||||||
|
if [ $sysName == 'Darwin' ]; then |
||||||
|
echo "jenkins mac no install!" |
||||||
|
else |
||||||
|
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo |
||||||
|
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key |
||||||
|
yum -y install jenkins |
||||||
|
fi |
||||||
|
|
||||||
|
echo '安装完成' > $install_tmp |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
Uninstall_walle() |
||||||
|
{ |
||||||
|
rm -rf $serverPath/jenkins |
||||||
|
echo "卸载完成" > $install_tmp |
||||||
|
} |
||||||
|
|
||||||
|
action=$1 |
||||||
|
if [ "${1}" == 'install' ];then |
||||||
|
Install_walle |
||||||
|
else |
||||||
|
Uninstall_walle |
||||||
|
fi |
@ -0,0 +1,99 @@ |
|||||||
|
function str2Obj(str){ |
||||||
|
var data = {}; |
||||||
|
kv = str.split('&'); |
||||||
|
for(i in kv){ |
||||||
|
v = kv[i].split('='); |
||||||
|
data[v[0]] = v[1]; |
||||||
|
} |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
function pPost(method,args,callback, title){ |
||||||
|
var _args = null;
|
||||||
|
if (typeof(args) == 'string'){ |
||||||
|
_args = JSON.stringify(str2Obj(args)); |
||||||
|
} else { |
||||||
|
_args = JSON.stringify(args); |
||||||
|
} |
||||||
|
|
||||||
|
var _title = '正在获取...'; |
||||||
|
if (typeof(title) != 'undefined'){ |
||||||
|
_title = title; |
||||||
|
} |
||||||
|
|
||||||
|
var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 }); |
||||||
|
$.post('/plugins/run', {name:'walle', func:method, args:_args}, function(data) { |
||||||
|
layer.close(loadT); |
||||||
|
if (!data.status){ |
||||||
|
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); |
||||||
|
return; |
||||||
|
} |
||||||
|
if(typeof(callback) == 'function'){ |
||||||
|
callback(data); |
||||||
|
} |
||||||
|
},'json');
|
||||||
|
} |
||||||
|
|
||||||
|
function pPostCallbak(method, version, args,callback){ |
||||||
|
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||||
|
|
||||||
|
var req_data = {}; |
||||||
|
req_data['name'] = 'walle'; |
||||||
|
req_data['func'] = method; |
||||||
|
args['version'] = version; |
||||||
|
|
||||||
|
if (typeof(args) == 'string'){ |
||||||
|
req_data['args'] = JSON.stringify(str2Obj(args)); |
||||||
|
} else { |
||||||
|
req_data['args'] = JSON.stringify(args); |
||||||
|
} |
||||||
|
|
||||||
|
$.post('/plugins/callback', req_data, function(data) { |
||||||
|
layer.close(loadT); |
||||||
|
if (!data.status){ |
||||||
|
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if(typeof(callback) == 'function'){ |
||||||
|
callback(data); |
||||||
|
} |
||||||
|
},'json');
|
||||||
|
} |
||||||
|
|
||||||
|
function initEnv(){ |
||||||
|
pPost('init_env', {}, function(data){ |
||||||
|
layer.msg(data.data,{icon:1,time:6000,shade: [0.3, '#000']}); |
||||||
|
},'初始化环境'); |
||||||
|
} |
||||||
|
|
||||||
|
function initData(){ |
||||||
|
pPost('init_data', {}, function(data){ |
||||||
|
layer.msg(data.data,{icon:1,time:6000,shade: [0.3, '#000']}); |
||||||
|
},'初始化数据'); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
function pluginCmd(){ |
||||||
|
var serviceCon ='<p class="status">当前可以运行的命令:<span></span><span style="color: #20a53a;margin-left: 3px;" class="glyphicon"></span></p>\ |
||||||
|
<div class="sfm-opt">\ |
||||||
|
<button class="btn btn-default btn-sm" onclick="initEnv()">初始化环境</button>\ |
||||||
|
<button class="btn btn-default btn-sm" onclick="initData()">初始化数据</button>\ |
||||||
|
</div>'; |
||||||
|
$(".soft-man-con").html(serviceCon); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function pRead(){ |
||||||
|
var readme = '<ul class="help-info-text c7">'; |
||||||
|
readme += '<li>使用默认walle端口5000,如有需要自行修改</li>'; |
||||||
|
readme += '<li>修改配置正确后:</li>'; |
||||||
|
readme += '<li>手动[初始化环境]:sh admin.sh init</li>'; |
||||||
|
readme += '<li>手动[初始化数据]:sh admin.sh migration</li>'; |
||||||
|
readme += '<li><a target="_blank" href="https://walle-web.io/docs/installation_docker.html">官方文档</a></li>'; |
||||||
|
readme += '</ul>'; |
||||||
|
|
||||||
|
$('.soft-man-con').html(readme);
|
||||||
|
} |
Loading…
Reference in new issue