pull/109/head
Mr Chen 7 years ago
parent 5bfed66c11
commit 5b73b73f16
  1. 8
      class/core/public.py
  2. 67
      plugins/memcached/index.py

@ -46,6 +46,14 @@ def getRootDir():
return os.path.dirname(os.path.dirname(getRunDir())) return os.path.dirname(os.path.dirname(getRunDir()))
def getPluginDir():
return getRunDir() + '/plugins'
def getServerDir():
return getRootDir() + '/server'
def getOs(): def getOs():
os = execShell('uname') os = execShell('uname')
return os[0].lower().strip() return os[0].lower().strip()

@ -9,6 +9,32 @@ sys.path.append(os.getcwd() + "/class/core")
import public import public
def getAppName():
return 'memcached'
def getPluginDir():
return public.getPluginDir() + '/' + getAppName()
def getServerDir():
return public.getServerDir() + '/' + getAppName()
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(): def status():
data = public.execShell( data = public.execShell(
"ps -ef|grep memcached |grep -v grep | grep -v python | awk '{print $2}'") "ps -ef|grep memcached |grep -v grep | grep -v python | awk '{print $2}'")
@ -20,14 +46,17 @@ def status():
def initDreplace(): def initDreplace():
file_tpl = getConf() file_tpl = getConf()
file_bin = os.getcwd() + '/plugins/memcached/init.d/memcached' service_path = os.path.dirname(os.getcwd())
if os.path.exists(file_bin): initD_path = getServerDir() + '/init.d'
return file_bin if not os.path.exists(initD_path):
os.mkdir(initD_path)
file_bin = initD_path + '/memcached'
content = public.readFile(file_tpl) # if os.path.exists(file_bin):
# return file_bin
service_path = os.path.dirname(os.getcwd()) content = public.readFile(file_tpl)
content = content.replace('{$SERVER_PATH}', service_path) content = content.replace('{$SERVER_PATH}', service_path)
public.writeFile(file_bin, content) public.writeFile(file_bin, content)
@ -106,22 +135,28 @@ def runInfo():
return public.getJson({}) return public.getJson({})
def getConf():
path = os.getcwd() + "/plugins/memcached/init.d/memcached.tpl"
return path
def saveConf(): def saveConf():
args = sys.argv[2] # 设置memcached缓存大小
if args == '': import re
return 'fail' confFile = getConf()
try:
print args 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'
if __name__ == "__main__": if __name__ == "__main__":
func = sys.argv[1] func = sys.argv[1]
print sys.argv
if func == 'run_info': if func == 'run_info':
print runInfo() print runInfo()
elif func == 'conf': elif func == 'conf':

Loading…
Cancel
Save