diff --git a/plugins/pm2/index.html b/plugins/pm2/index.html
index bcec2236a..9f0707e74 100755
--- a/plugins/pm2/index.html
+++ b/plugins/pm2/index.html
@@ -3,7 +3,7 @@
diff --git a/plugins/pm2/index.py b/plugins/pm2/index.py
index 5d2dc1ea8..32f2b354b 100755
--- a/plugins/pm2/index.py
+++ b/plugins/pm2/index.py
@@ -75,8 +75,8 @@ def pm2NVMDir():
__SR = '''#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
-export HOME=/root
-source %s/nvm.sh && ''' % pm2NVMDir()
+export HOME=%s
+source %s/nvm.sh && ''' % (getServerDir(), pm2NVMDir())
__path = getServerDir() + '/list'
@@ -230,11 +230,76 @@ def pm2VerList():
# print cmd
tmp = public.execShell(cmd)
result['list'] = re.findall(rep, tmp[0])
- tmp = public.execShell("nvm version")
+ tmp = public.execShell(__SR + "nvm version")
result['version'] = tmp[0].strip()
return public.returnJson(True, 'ok', result)
+def setNodeVersion():
+ args = getArgs()
+ data = checkArgs(args, ['version'])
+ if not data[0]:
+ return data[1]
+ # 切换Node版本
+ version = args['version'].replace('v', '')
+ estr = '''
+export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node && nvm install %s
+nvm use %s
+nvm alias default %s
+oldreg=`npm get registry`
+npm config set registry http://registry.npm.taobao.org/
+npm install pm2 -g
+npm config set registry $oldreg
+''' % (version, version, version)
+ cmd = __SR + estr
+ public.execShell(cmd)
+ return public.returnJson(True, '已切换至[' + version + ']')
+
+
+def getMod():
+ cmd = __SR + "npm list --depth=0 -global"
+ tmp = public.execShell(cmd)
+ modList = tmp[0].replace("│", "").replace("└", "").replace(
+ "─", "").replace("┴", "").replace("┘", "").strip().split()
+ result = []
+ for m in modList:
+ mod = {}
+ tmp = m.split('@')
+ if len(tmp) < 2:
+ continue
+ mod['name'] = tmp[0]
+ mod['version'] = tmp[1]
+ result.append(mod)
+
+ return public.returnJson(True, 'OK', result)
+
+
+# 安装库
+def installMod():
+ args = getArgs()
+ data = checkArgs(args, ['mname'])
+ if not data[0]:
+ return data[1]
+
+ mname = args['mname']
+ public.execShell(__SR + 'npm install ' + mname + ' -g')
+ return public.returnJson(True, '安装成功!')
+
+
+def uninstallMod():
+ args = getArgs()
+ data = checkArgs(args, ['mname'])
+ if not data[0]:
+ return data[1]
+
+ mname = args['mname']
+ myNot = ['pm2', 'npm']
+ if mname in myNot:
+ return public.returnJson(False, '不能卸载[' + mname + ']')
+ public.execShell(__SR + 'npm uninstall ' + mname + ' -g')
+ return public.returnJson(True, '卸载成功!')
+
+
if __name__ == "__main__":
func = sys.argv[1]
if func == 'status':
@@ -257,5 +322,13 @@ if __name__ == "__main__":
print pm2Log()
elif func == 'versions':
print pm2VerList()
+ elif func == 'set_node_version':
+ print setNodeVersion()
+ elif func == 'mod_list':
+ print getMod()
+ elif func == 'install_mod':
+ print installMod()
+ elif func == 'uninstall_mod':
+ print uninstallMod()
else:
print 'error'
diff --git a/plugins/pm2/install.sh b/plugins/pm2/install.sh
index fbdc0bb8a..19fefa068 100755
--- a/plugins/pm2/install.sh
+++ b/plugins/pm2/install.sh
@@ -11,12 +11,12 @@ serverPath=$(dirname "$rootPath")
install_tmp=${rootPath}/tmp/bt_install.pl
-npm install pm2 -g
-curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
-
Install_pm2()
{
echo '正在安装脚本文件...' > $install_tmp
+ npm install pm2 -g
+ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
+
mkdir -p $serverPath/pm2
echo '1.0' > $serverPath/pm2/version.pl
echo '安装完成' > $install_tmp
diff --git a/plugins/pm2/js/pm2.js b/plugins/pm2/js/pm2.js
index 62c4d0e4b..fd7ee68a4 100755
--- a/plugins/pm2/js/pm2.js
+++ b/plugins/pm2/js/pm2.js
@@ -117,8 +117,10 @@ function getNodeVersions(){
});
pm2Post('versions', '', function(data){
- console.log(data);
- return;
+
+ var rdata = $.parseJSON(data.data);
+ console.log(rdata);
+ var versions = rdata.data;
var opt = '';
for(var i=0;i
\
- \
+ \
\
- 当前版本为['+versions.version+']
\
- 版本切换是全局的,切换版本后可能影响您正在运行的项目
\
\
';
- // $("#webEdit-con").html(con);
-
$(".soft-man-con").html(con);
});
}
+
+//切换版本
+function setNodeVersion(){
+ var version = $("select[name='versions']").val();
+ var data = "version="+version;
+ pm2Post('set_node_version', data, function(data){
+ var rdata = $.parseJSON(data.data);
+ layer.msg(rdata.msg,{icon:rdata.status?1:2});
+ if(rdata.status) {
+ getNodeVersions();
+ }
+ });
+}
+
+
+//取模块列表
+function getModList(){
+ var con = '