diff --git a/plugins/gogs/index.html b/plugins/gogs/index.html
index cb71e7fd2..4aa017978 100755
--- a/plugins/gogs/index.html
+++ b/plugins/gogs/index.html
@@ -14,40 +14,4 @@
\ No newline at end of file
diff --git a/plugins/gogs/index.py b/plugins/gogs/index.py
index 172bebf74..c8792b1ac 100755
--- a/plugins/gogs/index.py
+++ b/plugins/gogs/index.py
@@ -4,5 +4,228 @@
import time
import os
import sys
+
sys.path.append("/usr/local/lib/python2.7/site-packages")
import psutil
+
+sys.path.append(os.getcwd() + "/class/core")
+import public
+
+
+app_debug = False
+if public.getOs() == 'darwin':
+ app_debug = True
+
+
+def getPluginName():
+ return 'gogs'
+
+
+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 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(':')
+ tmp[t[0]] = t[1]
+ return tmp
+
+
+def status():
+ data = public.execShell(
+ "ps -ef|grep " + getPluginName() + " |grep -v grep | grep -v python | awk '{print $2}'")
+ if data[0] == '':
+ return 'stop'
+ return 'start'
+
+
+def initDreplace():
+
+ file_tpl = getConf()
+ service_path = public.getServerDir()
+
+ 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
+
+ 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 start():
+ file = initDreplace()
+ data = public.execShell(file + ' start')
+ if data[1] == '':
+ return 'ok'
+ return 'fail'
+
+
+def stop():
+ file = initDreplace()
+ data = public.execShell(file + ' stop')
+ if data[1] == '':
+ return 'ok'
+ return 'fail'
+
+
+def restart():
+ file = initDreplace()
+ data = public.execShell(file + ' reload')
+ if data[1] == '':
+ return 'ok'
+ return 'fail'
+
+
+def reload():
+ file = initDreplace()
+ data = public.execShell(file + ' reload')
+ if data[1] == '':
+ return 'ok'
+ return 'fail'
+
+
+def runInfo():
+ # 获取memcached状态
+ import telnetlib
+ import re
+
+ try:
+ tn = telnetlib.Telnet('127.0.0.1', 11211)
+ tn.write(b"stats\n")
+ tn.write(b"quit\n")
+ data = tn.read_all()
+ if type(data) == bytes:
+ data = data.decode('utf-8')
+ data = data.replace('STAT', '').replace('END', '').split("\n")
+ result = {}
+ res = ['cmd_get', 'get_hits', 'get_misses', 'limit_maxbytes', 'curr_items', 'bytes',
+ 'evictions', 'limit_maxbytes', 'bytes_written', 'bytes_read', 'curr_connections']
+ for d in data:
+ if len(d) < 3:
+ continue
+ t = d.split()
+ if not t[0] in res:
+ continue
+ result[t[0]] = int(t[1])
+ result['hit'] = 1
+ if result['get_hits'] > 0 and result['cmd_get'] > 0:
+ result['hit'] = float(result['get_hits']) / \
+ float(result['cmd_get']) * 100
+
+ conf = public.readFile(getConf())
+ result['bind'] = re.search('IP=(.+)', conf).groups()[0]
+ result['port'] = int(re.search('PORT=(\d+)', conf).groups()[0])
+ result['maxconn'] = int(re.search('MAXCONN=(\d+)', conf).groups()[0])
+ result['cachesize'] = int(
+ re.search('CACHESIZE=(\d+)', conf).groups()[0])
+ return public.getJson(result)
+ except Exception, e:
+ 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()
+ if os_name == 'darwin':
+ return "Apple Computer does not support"
+ initd_bin = getInitDFile()
+ if os.path.exists(initd_bin):
+ return 'ok'
+ return 'fail'
+
+
+def initdInstall():
+ import shutil
+ if not app_debug:
+ os_name = public.getOs()
+ if os_name == 'darwin':
+ return "Apple Computer does not support"
+
+ mem_bin = initDreplace()
+ initd_bin = getInitDFile()
+ shutil.copyfile(mem_bin, initd_bin)
+ public.execShell('chmod +x ' + initd_bin)
+ return 'ok'
+
+
+def initdUinstall():
+ if not app_debug:
+ os_name = public.getOs()
+ if os_name == 'darwin':
+ return "Apple Computer does not support"
+ initd_bin = getInitDFile()
+ os.remove(initd_bin)
+ return 'ok'
+
+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_info':
+ print runInfo()
+ elif func == 'conf':
+ print getConf()
+ elif func == 'save_conf':
+ print saveConf()
+ else:
+ print 'fail'
diff --git a/plugins/gogs/install.sh b/plugins/gogs/install.sh
new file mode 100755
index 000000000..c791085bf
--- /dev/null
+++ b/plugins/gogs/install.sh
@@ -0,0 +1,67 @@
+#!/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/bt_install.pl
+
+
+GOGS_DOWNLOAD='https://dl.gogs.io'
+
+getOs(){
+ os=`uname`
+ if [ "Darwin" == "$os" ];then
+ echo 'darwin'
+ else
+ echo 'linux'
+ fi
+ return 0
+}
+
+getBit(){
+ echo `getconf LONG_BIT`
+}
+
+
+Install_gogs()
+{
+ mkdir -p $serverPath/source/gogs
+
+ echo '正在安装脚本文件...' > $install_tmp
+ version=$1
+ os=`getOs`
+
+ if [ "darwin" == "$os" ];then
+ file=gogs_${version}_darwin_amd64.zip
+ else
+ file=gogs_${version}_liunx_amd64.zip
+ fi
+
+ if [ ! -f $serverPath/source/gogs/$file ];then
+ wget -O $serverPath/source/gogs/$file ${GOGS_DOWNLOAD}/${version}/${file}
+ fi
+
+ cd $serverPath/source/gogs && unzip -o $file -d gogs_${version}
+ mv $serverPath/source/gogs/gogs_${version}/gogs/ $serverPath/gogs
+ echo $version > $serverPath/gogs/version.pl
+
+ echo '安装完成' > $install_tmp
+}
+
+Uninstall_gogs()
+{
+ rm -rf $serverPath/csvn
+}
+
+
+action=$1
+version=$2
+if [ "${1}" == 'install' ];then
+ Install_gogs $version
+else
+ Uninstall_gogs $version
+fi