Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
482 views
in Technique[技术] by (71.8m points)

node.js processes with the same name in forever are closed when trying to close only one

I am deploying two node.js apps on the aws, the two apps are in the paths shown as

/home/ubuntu/nodes/app1/app.js
/home/ubuntu/nodes/app2/app.js

respectively

to run the node.js apps in the background, I used forever to start two apps, so like

   $ sudo forever start /home/ubuntu/nodes/app1/app.js
   $ sudo forever start /home/ubuntu/nodes/app2/app.js

so forever works well by running the two node.js apps in the background process. However, when I tried to stop one process with forever command like this.

   $ sudo forever stop /home/ubuntu/nodes/app1/app.js

unexpectedly, both node.js process are closed with info like this

info:    Forever stopped process:
data:        uid  command         script forever pid   logfile                 uptime
[0] r2pZ /usr/bin/nodejs app.js 24852   24854 /root/.forever/r2pZ.log 0:0:1:14.775
[1] 9f2h /usr/bin/nodejs app.js 24870   24872 /root/.forever/9f2h.log 0:0:0:58.733

I assume it is because two node.js process has the same name - app.js, how to avoid this by close only one process

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use an uid (see here):

$ sudo forever --uid "app1" start app.js
$ sudo forever --uid "app2" start app.js

And to stop:

$ sudo forever stop app1

Update
The --uid option is deprecated. Now you can use the --pidFile option. Example:

forever start --pidFile /some/path/app1.pid app.js
forever start --pidFile /some/path/app2.pid app.js

And to stop:

forever stop --pidFile /some/path/app1.pid

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...