diff --git a/plugins/memcached/index.html b/plugins/memcached/index.html
index 2b6a419d1..1919a969a 100755
--- a/plugins/memcached/index.html
+++ b/plugins/memcached/index.html
@@ -3,9 +3,8 @@
diff --git a/plugins/memcached/index.py b/plugins/memcached/index.py
index 87b42d339..c5883f7ff 100755
--- a/plugins/memcached/index.py
+++ b/plugins/memcached/index.py
@@ -19,8 +19,8 @@ def status():
def initDreplace():
- file_tpl = os.getcwd() + '/plugins/memcached/init.d/memcached.tpl'
- file_bin = getConf()
+ file_tpl = getConf()
+ file_bin = os.getcwd() + '/plugins/memcached/init.d/memcached'
if os.path.exists(file_bin):
return file_bin
@@ -28,7 +28,7 @@ def initDreplace():
content = public.readFile(file_tpl)
service_path = os.path.dirname(os.getcwd())
- content = content.replace('{$PATH}', service_path)
+ content = content.replace('{$SERVER_PATH}', service_path)
public.writeFile(file_bin, content)
public.execShell('chmod +x ' + file_bin)
@@ -71,47 +71,63 @@ def runInfo():
# 获取memcached状态
import telnetlib
import re
- 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)
+ 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 getConf():
path = os.getcwd() + "/plugins/memcached/init.d/memcached.tpl"
return path
+
+def saveConf():
+ args = sys.argv[2]
+ if args == '':
+ return 'fail'
+
+ print args
+
+
if __name__ == "__main__":
func = sys.argv[1]
+ print sys.argv
if func == 'run_info':
print runInfo()
elif func == 'conf':
print getConf()
+ elif func == 'save_conf':
+ print saveConf()
elif func == 'status':
print status()
elif func == 'start':
@@ -122,3 +138,5 @@ if __name__ == "__main__":
print restart()
elif func == 'reload':
print reload()
+ else:
+ print 'fail'
diff --git a/plugins/memcached/init.d/memcached.tpl b/plugins/memcached/init.d/memcached.tpl
index 4fad18e8a..440e7f275 100755
--- a/plugins/memcached/init.d/memcached.tpl
+++ b/plugins/memcached/init.d/memcached.tpl
@@ -27,9 +27,11 @@ OPTIONS=""
RETVAL=0
prog="memcached"
+MEM_PATH={$SERVER_PATH}/memcached
+
start () {
echo -n $"Starting $prog: "
- {$PATH}/memcached/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P {$PATH}/memcached/memcached.pid $OPTIONS
+ $MEM_PATH/bin/memcached -d -l $IP -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P $MEM_PATH/memcached.pid $OPTIONS
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
@@ -39,16 +41,16 @@ start () {
}
stop () {
echo -n $"Stopping $prog: "
- if [ ! -e {$PATH}/memcached/$prog.pid ]; then
+ if [ ! -e $MEM_PATH/$prog.pid ]; then
echo -n $"$prog is not running."
exit 1
fi
- kill `cat {$PATH}/memcached/memcached.pid`
+ kill `cat $MEM_PATH/memcached.pid`
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
else
- rm -f {$PATH}/memcached/memcached.pid
+ rm -f ${MEM_PATH}/memcached.pid
echo " done"
fi
}
diff --git a/plugins/memcached/js/mem.js b/plugins/memcached/js/mem.js
index e117a542b..c781cc8bb 100755
--- a/plugins/memcached/js/mem.js
+++ b/plugins/memcached/js/mem.js
@@ -5,12 +5,18 @@
function memcachedStatus() {
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
$.post('/plugins/run', {name:'memcached', func:'run_info'}, function(data) {
- if (!data.status){
+ layer.close(loadT);
+
+ if (!data.status){
showMsg(data.msg, function(){}, null,13000);
return;
}
- layer.close(loadT);
+
var rdata = $.parseJSON(data.data);
+ if ($.isEmptyObject(rdata)){
+ showMsg('memcached服务没有启动!', function(){}, undefined, 3000);
+ return;
+ }
var Con = '
\
\
| 字段 | 当前值 | 说明 | \
@@ -38,17 +44,29 @@ function memcachedStatus() {
//memcached性能调整
function memcachedCache() {
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 });
- $.get('/ajax?action=GetMemcachedStatus', function(rdata) {
+ $.post('/plugins/run', {name:'memcached', func:'run_info'}, function(data) {
layer.close(loadT);
+
+ if (!data.status){
+ showMsg(data.msg, function(){}, null,13000);
+ return;
+ }
+
+ var rdata = $.parseJSON(data.data);
+ if ($.isEmptyObject(rdata)){
+ showMsg('memcached服务没有启动!', function(){}, undefined, 3000);
+ return;
+ }
+
var memCon = '\
BindIP监听IP,请勿随意修改
\
PORT监听端口,一般无需修改
\
CACHESIZEMB,缓存大小,建议不要大于512M
\
MAXCONN最大连接数,建议不要大于40960
\
-
\
+
\
'
$(".soft-man-con").html(memCon);
- });
+ },'json');
}
//memcached提交配置
@@ -79,9 +97,10 @@ function setMemcachedConf() {
layer.msg('最大连接数过小', { icon: 2 });
return;
}
+
var loadT = layer.msg('正在保存...', { icon: 16, time: 0, shade: 0.3 });
- $.post('/ajax?action=SetMemcachedCache', data, function(rdata) {
+ $.post('/plugins/run', {name:'memcached', func:'save_conf',args:JSON.stringify(data) }, function(rdata) {
layer.close(loadT);
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
- });
+ },'json');
}
\ No newline at end of file