4

My case is this:

I am running a node.js server at domain.com:54321

The command 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.com:67890

forever stop 0

But if I want to start again the recently stopped node.js server domain.com: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 commands that will make sure that every instance, resource of that server is stopped, so I can start using it again immediately?

Thank you

EnexoOnoma
  • 8,454
  • 18
  • 94
  • 179

6 Answers6

2

You 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 | command          | 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

Akhilesh Kumar
  • 4,127
  • 1
  • 11
  • 10
0

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
Victor
  • 5,043
  • 3
  • 41
  • 55
0

Run forever list then forever stop **id**

Here is a sample output

$ forever list
info:    Forever processes running
data:        uid  command                                                  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]

xdeepakv
  • 7,835
  • 2
  • 22
  • 32
0

May be kill all node processes forcefully if that is what you want.

follow this answer to kill all node process : https://stackoverflow.com/a/14790921/5055850

Rahul Tarafdar
  • 314
  • 2
  • 4
0

check this, if your port are 8000 , it will stop forever

sudo kill -9 `sudo lsof -t -i:8000`
Suresh Sekar
  • 928
  • 6
  • 7
0

I had the same problem. For me this worked: forever stopall.

SamBot
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 03 '22 at 18:23