This commit is contained in:
Mr Chen
2018-12-14 17:39:47 +08:00
parent fa8fc2cc70
commit 4bb740a5a0
3 changed files with 117 additions and 39 deletions
+4 -6
View File
@@ -1,10 +1,9 @@
<div class="bt-form">
<div class="bt-w-main">
<div class="bt-w-menu">
<p class="bgw" onclick="pluginService('redis');">服务</p>
<p onclick="pluginInitD('redis');">自启动</p>
<p onclick="pluginConfig('redis');">配置修改</p>
<p onclick="redisStatus();">负载状态</p>
<p class="bgw" onclick="pluginService('gogs');">服务</p>
<p onclick="pluginInitD('gogs');">自启动</p>
<p onclick="pluginConfig('gogs');">配置修改</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con"></div>
@@ -12,6 +11,5 @@
</div>
</div>
<script type="text/javascript">
pluginService('redis');
pluginService('gogs');
</script>
+17 -33
View File
@@ -35,20 +35,28 @@ def getInitDFile():
return '/etc/init.d/' + getPluginName()
def getConf():
path = getPluginDir() + "/init.d/memcached.tpl"
return path
def getArgs():
args = sys.argv[2:]
tmp = {}
for i in range(len(args)):
t = args[i].split(':')
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 getConf():
path = getPluginDir() + "/init.d/gogs.tpl"
return path
def status():
data = public.execShell(
"ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
@@ -65,10 +73,7 @@ def initDreplace():
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
file_bin = initD_path + '/memcached'
# if os.path.exists(file_bin):
# return file_bin
file_bin = initD_path + '/' + getPluginName()
content = public.readFile(file_tpl)
content = content.replace('{$SERVER_PATH}', service_path)
@@ -81,6 +86,7 @@ def initDreplace():
def start():
file = initDreplace()
data = public.execShell(file + ' start')
print data
if data[1] == '':
return 'ok'
return 'fail'
@@ -149,26 +155,6 @@ def runInfo():
return public.getJson({})
def saveConf():
# 设置memcached缓存大小
import re
confFile = getConf()
try:
args = getArgs()
content = public.readFile(confFile)
content = re.sub('IP=.+', 'IP=' + args['ip'], content)
content = re.sub('PORT=\d+', 'PORT=' + args['port'], content)
content = re.sub('MAXCONN=\d+', 'MAXCONN=' + args['maxconn'], content)
content = re.sub('CACHESIZE=\d+', 'CACHESIZE=' +
args['cachesize'], content)
public.writeFile(confFile, content)
reload()
return 'ok'
except Exception as e:
pass
return 'fail'
def initdStatus():
if not app_debug:
os_name = public.getOs()
@@ -225,7 +211,5 @@ if __name__ == "__main__":
print runInfo()
elif func == 'conf':
print getConf()
elif func == 'save_conf':
print saveConf()
else:
print 'fail'
+96
View File
@@ -0,0 +1,96 @@
#!/bin/sh
#
# /etc/rc.d/init.d/gogs
#
# Runs the Gogs
#
#
# chkconfig: - 85 15
#
### BEGIN INIT INFO
# Provides: gogs
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: mysql postgresql
# Should-Stop: mysql postgresql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start gogs at boot time.
# Description: Control gogs.
### END INIT INFO
# Source function library.
if [ -f /etc/init.d/functions ];then
. /etc/init.d/functions
fi
# Default values
NAME=gogs
GOGS_HOME={$SERVER_PATH}/gogs
GOGS_PATH=${GOGS_HOME}/$NAME
GOGS_USER=midoks
SERVICENAME="Gogs"
LOCKFILE=/tmp/gogs.lock
LOGPATH=${GOGS_HOME}/log
LOGFILE=${LOGPATH}/gogs.log
RETVAL=0
status(){
isStart=`ps -ef|grep 'gogs web' |grep -v grep|awk '{print $2}'`
if [ "$isStart" == '' ];then
echo "${SERVICENAME} not running"
else
echo "${SERVICENAME}(pid $(echo $isStart)) already running"
fi
}
start() {
isStart=`ps -ef|grep 'gogs web' |grep -v grep|awk '{print $2}'`
if [ "$isStart" != '' ];then
echo "${SERVICENAME}(pid $(echo $isStart)) already running"
return $RETVAL
fi
cd ${GOGS_HOME}
echo "Starting ${SERVICENAME}: \c"
${GOGS_PATH} web > ${LOGFILE} 2>&1 &
RETVAL=$?
[ $RETVAL = 0 ] && touch ${LOCKFILE} && echo "\033[32mdone\033[0m"
return $RETVAL
}
stop() {
cd ${GOGS_HOME}
echo "Shutting down ${SERVICENAME}: \c"
pkill ${NAME}
RETVAL=$?
[ $RETVAL = 0 ] && rm -f ${LOCKFILE} && echo "\033[32mdone\033[0m"
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
reload)
stop
start
;;
*)
echo "Usage: ${NAME} {start|stop|status|restart}"
exit 1
;;
esac
exit $RETVAL