How to run an independent bash script in nodejs

So I would like to run a script which kills my nodejs process and runs another one in another screen window. When I run the command from the console it works, but when run from nodejs script the kill part gets executed but the server is never run.

filelog('Attempting restartNodejs with PID: ' + pid
    + ' serverjsLocation: ' + serverjsLocation);
filelog('kill ' + pid + ';screen -d -m -L nodejs ' + serverjsLocation);
//return;

exec('kill ' + pid + ';screen -d -m -L nodejs ' + serverjsLocation);

and the log is

Attempting restartNodejs with PID: 29685 serverjsLocation: /home/git/Gitorade/server.js
kill 29685;screen -d -m -L nodejs /home/git/Gitorade/server.js

but the server is not run. ps -e | grep nodejs ps -e | grep nodejs returns nothing while at the first run it does output the process.

My guess would be that it's run as a fork so somehow when I kill the nodejs the screen command never gets executed because I can in no way get any response or log out of the action. The screen.0 log is empty after that command.

How do I run this exec independently so that it does not get killed after kill ?

链接地址: http://www.djcxy.com/p/52720.html

上一篇: 在每个服务器重新启动后,端口“已被使用”

下一篇: 如何在nodejs中运行独立的bash脚本