My case is this:
I am running a node.js server at domain:54321
The mand I use to start the server is:
forever start -l forever.log -a -o out.log -e err.log index.js
However, there are some cases where our code gets into a high demanding function, causing the script to work very slow or unresponsive. We are trying to optimize it.
In that case, I stop the server, and start a new one if needed, lets say domain:67890
forever stop 0
But if I want to start again the recently stopped node.js server domain:54321
(or restart it instead of stopping it) with this, I was expecting the processes to stop and run as fresh and fast again.
The thing that if I start it again, or restart it, it continues to go high on resources. I found out that I need to leave it for a couple of hours to start it again.
My question is, are there any other mands that will make sure that every instance, resource of that server is stopped, so I can start using it again immediately?
Thank you
My case is this:
I am running a node.js server at domain.:54321
The mand I use to start the server is:
forever start -l forever.log -a -o out.log -e err.log index.js
However, there are some cases where our code gets into a high demanding function, causing the script to work very slow or unresponsive. We are trying to optimize it.
In that case, I stop the server, and start a new one if needed, lets say domain.:67890
forever stop 0
But if I want to start again the recently stopped node.js server domain.:54321
(or restart it instead of stopping it) with this, I was expecting the processes to stop and run as fresh and fast again.
The thing that if I start it again, or restart it, it continues to go high on resources. I found out that I need to leave it for a couple of hours to start it again.
My question is, are there any other mands that will make sure that every instance, resource of that server is stopped, so I can start using it again immediately?
Thank you
Share Improve this question edited Mar 23, 2020 at 23:04 EnexoOnoma asked Mar 23, 2020 at 22:36 EnexoOnomaEnexoOnoma 8,84420 gold badges98 silver badges186 bronze badges 7- Try running 'forever list' and 'sudo forever list' after stopping your service, list needs to be empty – Alfredo Lanzetta Commented Mar 26, 2020 at 13:53
- @AlfredoLanzetta I do this, and they are indeed stopped. – EnexoOnoma Commented Mar 26, 2020 at 13:55
-
2
Try to run
forever.stopAll && forever.cleanUp
. I also suggest you to use PM2 instead of forever for your project. – Alfredo Lanzetta Commented Mar 26, 2020 at 14:02 -
@AlfredoLanzetta is
forever.stopAll
stops all running node.js servers? (I am asking this without testing it first because I will run this in the production) – EnexoOnoma Commented Mar 26, 2020 at 14:24 -
1
Use
pm2
, it works like a charm! – Christos Lytras Commented Mar 27, 2020 at 15:32
6 Answers
Reset to default 2You can stop a Forever daemon using the id of forever running using four different ways:
- index
- id
- uid
- pid
I can see one of the answer to covering the stopping a forever running daemon using pid, I can add for other methods.
List running Forever instances:
$ forever list
info: Forever processes running
|data: | index | uid | mand | script |forever pid|id | logfile |uptime |
|------|-------|-----|------------------|-------------|-----------|-----|------------------------|--------------|
|data: | [0] |f4Kt |/usr/bin/nodejs | src/index.js|2131 | 2146|/root/.forever/f4Kt.log | 0:0:0:11.485 |
$ forever stop 0
index
$ forever stop 2146
id
$ forever stop --uid f4Kt
uid
$ forever stop --pidFile 2131
pid
To make sure to stop the process you can use the pid option:
forever start -l forever.log -a -o out.log -e err.log --pidFile ~/app_pid index.js
forever stop --pidFile ~/app_pid
Run forever list
then forever stop **id**
Here is a sample output
$ forever list
info: Forever processes running
data: uid mand script forever pid id logfile uptime
data: [0] 9Xzw ng serve --host 0.0.0.0 --port 300 1111 2312 /home/ec2-user/.forever/9Xzw.log 1:3:20:50.412
data: [1] wOj1 npm run-script app-start-dev 29500 24978 /home/ec2-user/.forever/wOj1.log 0:0:5:3.433
Check your process id and kill
forever stop 0
OR forever stop 1
OR forever stop 2
Here 0, 1, 2 index of process, data:[0]
, data:[1]
May be kill all node processes forcefully if that is what you want.
follow this answer to kill all node process : https://stackoverflow./a/14790921/5055850
check this, if your port are 8000 , it will stop forever
sudo kill -9 `sudo lsof -t -i:8000`
I had the same problem. For me this worked: forever stopall.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745265932a4619456.html
评论列表(0条)