我想使用NodeJS执行pm2 restart IDOFMYAPP
......这可能吗?
类似的东西:
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("pm2 restart IDOFMYAPP", puts);
实际上,我想创建一个按钮来执行上面的代码,但是我的按钮位于我想要重启的应用程序的视图中...
编辑#1
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:904:11)
at Server._listen2 (net.js:1042:14)
at listen (net.js:1064:10)
at Server.listen (net.js:1138:5)
at Function.app.listen (C:\xampp\htdocs\CMS\node_modules\microscope-web\node_modules\express\lib\application.js:546:24)
at _.extend.run (C:\xampp\htdocs\CMS\node_modules\microscope-web\libs\Application.js:109:27)
at Application.extend.initialize (C:\xampp\htdocs\CMS\Application.js:23:10)
at Application (C:\xampp\htdocs\CMS\node_modules\microscope-web\libs\Application.js:31:19)
at new child (C:\xampp\htdocs\CMS\node_modules\microscope-web\libs\utils.js:17:27)
at C:\xampp\htdocs\CMS\bin\www:11:16
npm ERR! microscope_application@0.0.1 start: `node ./bin/www`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the microscope_application@0.0.1 start script.
npm ERR! This is most likely a problem with the microscope_application package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/www
npm ERR! You can get their info via:
npm ERR! npm owner ls microscope_application
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! cwd C:\xampp\htdocs\CMS
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm
编辑#2
var shell = require('shelljs');
shell.exec('pm2 restart IDOFMYAPP', function(code, output) {
console.log('Exit code:', code);
console.log('Program output:', output);
res.redirect('/');
});
答案 0 :(得分:0)
你可以这样做:
var shell = require('shelljs');
shell.exec('pm2 restart IDOFMYAPP', function(code, output) {
console.log('Exit code:', code);
console.log('Program output:', output);
});