EnexoOnoma
EnexoOnoma

Reputation: 8836

Node.js server is not stopping on forever stop 0

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

Upvotes: 4

Views: 4293

Answers (6)

SamBot
SamBot

Reputation: 1

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

Upvotes: 0

Suresh Sekar
Suresh Sekar

Reputation: 928

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

sudo kill -9 `sudo lsof -t -i:8000`

Upvotes: 0

Rahul Tarafdar
Rahul Tarafdar

Reputation: 314

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

Upvotes: 0

Akhilesh Kumar
Akhilesh Kumar

Reputation: 5055

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

Upvotes: 2

xdeepakv
xdeepakv

Reputation: 8125

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]

Upvotes: 0

Victor
Victor

Reputation: 5121

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

Upvotes: 0

Related Questions