diff --git a/plugins/gogs/index.html b/plugins/gogs/index.html index 4aa017978..fdd441d1e 100755 --- a/plugins/gogs/index.html +++ b/plugins/gogs/index.html @@ -1,10 +1,9 @@
-

服务

-

自启动

-

配置修改

-

负载状态

+

服务

+

自启动

+

配置修改

@@ -12,6 +11,5 @@
\ No newline at end of file diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py index c8792b1ac..14332b777 100755 --- a/plugins/gogs/index.py +++ b/plugins/gogs/index.py @@ -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' diff --git a/plugins/gogs/init.d/gogs.tpl b/plugins/gogs/init.d/gogs.tpl new file mode 100644 index 000000000..0eda7eb6c --- /dev/null +++ b/plugins/gogs/init.d/gogs.tpl @@ -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