I have a node application running as a daemon on the server with forever. After one of the updates, I tried to stop it (to restart later). But to my surprise forever stopall
has done nothing No forever processes running
was returned. Forever list
has returned the same. Both commands I tried with sudo as well.
The problem is that I can clearly see that node is still running (my app is working just fine). Any idea what was wrong?
P.S. I needed to roll update as fast as possible so I just rebooted the server. But I am still curious about this situation.
P.S.S after typing ps aux | grep app.js
ubuntu 1320 0.0 2.2 663040 23232 ? Ssl Sep12 0:00 /usr/bin/nodejs /usr/lib/node_modules/forever/bin/monitor node_app/app.js
ubuntu 1322 0.0 6.9 992564 70792 ? Sl Sep12 0:31 /usr/bin/nodejs /var/www/node_app/app.js
root 9739 0.0 0.0 10468 936 pts/0 S+ 11:09 0:00 grep --color=auto app.js
Why is this happening? I am running node app.js on amazon aws.
EDIT:
I´ve managed how to mark your apps in forever using a UID, and then not using
forever stopall
. This is a cleaner way, and will make forever to kill all the processes depending on the script.You just need to add the
--uid "scriptID"
parameter, and then all the processes depending on it, will be controlled together.To start a new daemon:
forever start --uid "demo" --sourceDir /home/procdir -l /home/log/logfile -o /home/log/outputfile -a -d -v taskName
To Stop a daemon:
forever stop -uid "demo"
-bash-4.1$ forever list
info: Forever processes running
data: uid command script forever pid id logfile uptime
data: [1] Test /usr/bin/node grunt serve:test 18217 18224 /home/admin/logs/test/forever.log 59:20:21:10.512
data: [2] Dev /usr/bin/node grunt serve:dev 18347 18354 /home/admin/logs/dev/forever.log 59:20:19:56.87
data: [3] Prod /usr/bin/node grunt serve:prod 20411 20418 /home/admin/logs/prod/forever.log 59:18:58:28.697
Anyway, you can also run (hands way) this command to to kill the processes: First, kill all forever tasks (this will prevent forever to run the task again when killing it):
forever list | grep your_app | `awk '/\[0\]/{print "forever stop "$8}'`
After that, when forever is killed, then now it´s time to kill your node_app
ps -efa | grep node | grep your_app | `awk '{ print "kill "$2}'`
I strongly recommend you to not using
kill
.forever --uid
will surely be the best solution.
Hope this solution helps you!