Determine what script a node process is running - node.js

I'm using PM2 on a Windows server to run a bunch of different scripts. I have found that sometimes when I issue a stop with PM2 it reports the process as stopped but the node process is still running.
I want to be able to determine what script is being run by the node process (as reported by Windows task manager). If I was binding to a port I could figure it out with net stat but these scripts don't listen on ports, rather they connect to Rabbit MQ.
If I can identify the task in Windows I can forcefully terminate it using task manager.

I think you're looking for tasklist /FI "Imagename eq node" (or something similar)
Related: https://superuser.com/questions/18830/is-there-a-command-in-windows-like-ps-aux-in-unix
Docs for tasklist: https://technet.microsoft.com/en-us/library/bb491010.aspx
Related, if your process is listening on a port and you know that number: How can you find out which process is listening on a port on Windows?
If you're connected to RabbitMQ your PID will be in the Consumers section of the queue, something like this: node-amqp-37997-0.5310617093928158 where 37997 is the PID of the process listening.

Related

How does PM2 manage to run multiple processes listening on the same port?

I wonder how pm2 allows my express app code to run unmodified in parallel processes. When I try to manually start another instance of my express app listening on e.g. port 3000, I always get error that port is already in use.
Does pm2 MODIFY the js code which is run to insert some tweaks in the middle, or does it emulate some sort of VM and then exposes just the one port of pm2 process to the world? What goes on behind the scene?
PM2 won't allow you to start the same script on the port again. If you use the pm2 start app.js -f option to force the script to start again, pm2 will repeatedly try starting up the script but will fail every time since that port is already in use. pm2 ls might show that there are two processes running, but in reality the second one is failing continuously and you can confirm the same by running the pm2 logs command.
If you're talking about the cluster mode of pm2, in that case pm2 just load balances the requests between multiple child processes using NodeJS's cluster module internally.

nodejs process keeps respawning

I can no longer access my node.js application. I see thee following behaviours.
1> netstat shows the server listening on the port I expect it to.
2> tcpdump shows traffic from my laptop on the server when I attempt to open the page.
3> When I try to kill the node process with kill -9 or pkill node nothing happens.
I see the pid for the node process is changing continuously as if it was constantly being restarted. I see posts similar to this but none of them have definitive answers.
I have stopped and started the node site as we all restarting the host. Which I don't like doing as a problem resolution as you don't really know what the underlying problem is.
I also don't see an error log for node.
Any advice or guidance on how to determine what the problem is would be appreciated.

DigitalOcean stop Node.js server running with nohup

I am running a Node.js server on a DigitalOcean droplet (with Ubuntu). I have worked out how to make it run when I'm not connected to it via Putty. However, just one issue: how do I stop it now?
I can see that control+C works when in the session, but what if I exit the session and come back? How will I stop the server then?
Also, will running it multiple times run multiple servers at once?
Thanks!
You really should be using a tool like supervisord (http://supervisord.org/) for your long-running processes.
But if you want to stop an already running process that you started with nohup then look up the process ID first (with ps aux and look/grep for your process) and then run kill <<pid>>.

Node-Inspector Failed to open socket

I am following the directions here: https://github.com/node-inspector/node-inspector
Pretty simple. npm install node-inspector. In one shell run node-inspector and in another run node --debug app.js. Shell spits out an localhost address with specific port for the debugger. Open that address in a browser — it loads your code. From there add breakpoints, debug network, etc..
But this does not work.
The following message endlessly logs in my shell:
Failed to open socket on port 5858, waiting 1000 ms before retrying
..and no connection is made.
So my question is has anyone had this problem and successfully found a solution. Would love to get this working, would be super useful. My only experience in server-side debuggers is Ruby's Byebug which was a piece of cake to set up.
The message you see is printed because there is another process listening on port 5858. Either a different application, or simply another instance of a node process under the debugger.
An update based on comments below this answer
If your application is running in a cluster mode via Node.js core module "cluster", then you end up with multiple worker processes, where each of them is trying to listen on port 5858.
Node Inspector cannot debug multiple worker processes at the same time. You have to pick one process and enable the debugger in that process only. When you start the app via node --debug, all processes try to enable the debugger, therefore you cannot use this command.
Instead, you have to:
Start your app without the debugger enabled.
Then you need to find the pid (process id) of the worker process you would like to debug.
Once you have the PID, you need to enable the debugger in the target process. You can run kill -1 <pid> on UNIX, or use node debug -p <pid> that works on all platforms. Don't forget to exit node debug before proceeding further.
Once the target process has debugger listening on 5858, you can start Node Inspector the usual way.
My answer is based on the following blog post: https://strongloop.com/strongblog/whats-new-nodejs-v0-12-debugging-clusters/, check it out for more details.

How to start Jetty with multiple standalone instances?

I am trying to start two instances of Jetty in different ports (one is 8080 and the other is 443).
I created two jetty.base directories using start.jar with the parameter --add-to-startd.
When I run "java -jar /opt/jetty/start.jar" in the first app directory it starts normally, port 8080.
When I run "java -jar /opt/jetty/start.jar" in the second app directory, it kills the first process. And after that starts normally, port 443.
If I change the order the same thing happens.
How can I run more than one instance of Jetty without one killing the other?
Jetty: jetty-distribution-9.3.0.M2
Java: jdk1.8.0_25
Operating system: Linux CentOS release 6.6
I found the problem, the process died because the server was out of memory.
I didn't see any Exception in the logs, but monitoring the machine, I saw that when the memory was close to 100% the process died.

Resources