Cannot kill NodeJS process that always keeps restarting - node.js

I started a node script inside WebStorm once. It is a VueJS application. It is running on localhost:5000. When I open it inside chrome, I can see that it first is not responding, and then it suddenly loads. That tells me that the process is always restarting and inside a loop.
When I run ps aux | grep node , I can see the process quickly changing the process ID. That confirms my observation. If I try to kill the process it tells me that there is no process with that ID because it restarted that quickly. The process also is starting when reboot the computer. I also completely uninstalled NodeJS from my computer, but strangely it is starting anyways. I'm on macOS and I don't know what I could try anymore.
ps aux | grep node output:
2959 0,0 0,0 4268464 740 s000 S+ 3:47pm 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox node

I don't have enough reputation to leave a comment on your question, so I'm writing here.
It seems like you're application somehow registered in the service which happened to me as well. Mine was CentOS7.
You can check if it's added into service and run automatically whenever the machine is on. The command is Linux ones, so I'm not sure whether it's gonna work on MacOS as well.
//check list
chkconfig --list
//turn off the automatic start
chkconfig [your application name] off
If changing service config by using above commands did not work, you can search for the Mac Service Script. I think service shell script are different. Again, my case was on CentOS7.
Hope it helps.

Related

Node JS process running under PM2 and file permissions

I have a small node.js (v13.5.0) server running under PM2 (v4.4.0) on a RHEL 7.6 box. As a part of it's function it writes a small CSV file to the disc for every incoming request. This app is writing these files with the perms (rw-r-----).
The user I am having PM2 executing my process as has umask set to 0022. I have confirmed this is effective as it works in other cases.
So the main problem is that I cannot get my pm2+node combo to use the umask to write files with the right permissions.
Any suggestions where i am going wrong?
Thanks in advance,
So using ps fu -u $USER i figured out that PM2 daemon process had been running since i first started it (started column) - which was way before I made the umask change. As a result it was running with an outdated environment.
I restarted it using pm2 kill && pm2 start && pm2 ping which should return a pong. Subsequent tests proved that this had fixed the issue.

How to stop Yarn Package Manager script from CLI

https://yarnpkg.com/en/docs/cli/
Is there a way to stop what is started from the command "yarn run"? Is my only option to lookup the process number and call kill on it?
The usual way ctrl-c should work. If it doesn't work, than you have bug in the script. The script's author missed handler for shutdown (SIGINT/SIGTERM/etc).
I had a similar issue having it running after ctl+c and then I thought, maybe it is just running on the cache
so went to http://localhost:3000/
ctrl+F5
which forces refresh without cache showed me that the actual project wasn't really running anymore!
;)
*hadn't it worked I would have had to sudo kill the 3000 port
I know this is a well-answered question. However, it behaved once very strange when I was running a sample React code which was auto-created by the create-react-app CLI, on my Windows 10.
After hitting Ctrl+C, which is the most suggested standard way to stop the yarn run, though I got back the command prompt, there was a ghost process lingering around there, which was still actively listening to 3000(default) port, and localhost:3000 was working as normal.
So finally this is how I fixed it:
netstat -ano | grep ":3000" (yeah, I ran this from my git-bash instead of command prompt!)
Noted down the PID of the line where it says LISTENING on 3000
Pressed Ctrl+Shift+Esc to open the Task Manager
Went to the Process tab
Right clicked on one of the headings, say Name
Selected PID --> This added the PID column to the display
Located the PID in question
Right clicked on it and clicked "End task"
Luckily Windows knew how to kill that misbehaving, ghost process and the port became free for me.
NOTE: Prior to the above-mentioned steps, I tried to kill that PID from git-bash using the famous (or notorious as per its meaning?? >8)) kill -9 command. It was responding back with no such PID msg, however netstat -ano was clearly displaying the PID and browser was proving that the ghost process is up and alive!!

Neo4j Server running problems on Linux

I am using Neo4j 2.0.3 Community server by installing it on my linux system (by unzipping the tar.gz). I got this error while I tried to start the server
WARNING! You are using an unsupported Java runtime.
process [50690]... waiting for server to be ready.neo4j-community-2.0.3/bin/neo4j: line 147: lsof : command not found
.neo4j-community-2.0.3/bin/neo4j: line 147: lsof : command not found
.neo4j-community-2.0.3/bin/neo4j: line 147: lsof : command not found
. Failed to start within 120 seconds.
Neo4j Server may have failed to start, please check the logs.
I checked for the solution for this and came to know that /usr/sbin had to be added to the path. On doing so and restarting the server, I got the following message
Another server-process is running with [40903], cannot start a new one. Exiting.
However, when I run the command neo4j staus , it says
Neo4j Server is not running
Can anybody please help me with how should I get started with it?
This is very late, but might help others.
If it tells you this, and you check that process id with, for example, ps aux | grep 40903, and it's not neo4j, the problem might be that the port is being used.
By default neo4j uses 7474, but can change this on the neo4j folder /conf/neo4j-server.properties and that was my problem, I had set the port to '22' which was being used. SO make sure it is set to a port that is open and available.
Hope this helps.
You might want to examine the startup script.
Another server-process is running with [40903], cannot start a new one. Exiting.
indicates (me to) that there might be a pid file (or the script uses them) which was written and is checked before attempting to start a new instances. This the normal thing to do.
I think you need to kill the other process using kill
You can see this answer for how to kill the process:
https://unix.stackexchange.com/questions/8916/when-should-i-not-kill-9-a-process
Otherwise, restarting the operating system will also do the job. For me, I normally start neo4j in the console, as in ./neo4j console. This makes it easier to stop the process.

Unable to restart rogue Jenkins on Ubuntu

I was configuring Jenkins last night to run some reporting plugins (codestyle, findbugs, cobertura). When I ran my build job it got hung up somewhere in codestyle, and the server ui became unresponsive.
Today I logged in to the server and the Jenkins log is reporting errors that look like the server ran out of memory, but more than that, I cannot seem to stop or restart the server. I have limited experience with services in linux.
Jenkins was installed on Ubuntu with atp. I have tried $ sudo /etc/init.d/jenkins restart but it reports
* Starting Jenkins Continuous Integration Server jenkins
The selected http port (8080) seems to be in use by another program
Please select another port to use for jenkins
When I try to run service jenkins status to get a pid to kill i get
2 instances of jenkins are running at the moment
but the pidfile /var/run/jenkins/jenkins.pid is missing
Running netstat and ps has identified the port being held by a jenkins instance.
How can I recover from this?
Mostly I was concerned about abruptly killing the Jenkins server while it has gone rogue. Something this tied into process with server connections and plugins makes me wary of taking a shotgun to the process.
That's exactly what I did. server jenkins status didn't work, so I got the process id from netstat -tulpn. kill -15 didn't work so I did kill -9, waited a respectful grieving period, then restarted the Jenkins service.
I will next be investigating the root problem of running out of memory in my Jenkins installation so hopefully this doesn't happen again while I am firewalled away from my server.
Where is your server hosted?
I had the same issue with AWS EC2 server.
Command lines did not work to reboot the server.
However, on AWS admin console, I did: EC2 -> restart and it works like a charm.
This may not be a solution but a workaround.
I was able to do
sudo ps aux | grep jenkins
To find a list of jenkins processes. Then I ran
sudo kill <pid>
And then finally
sudo service jenkins restart

how to automatically restart a node server?

We are finishing development of a project, the client is already using it but occasionally some errors occur - crashing the server.
I know I could register a service as 'upstart' script on linux, in order to have my node service restart when it crashes.
But our server is running other stuff, so we can't restart it.
Well, actually, while writing, I realize I have two questions then:
Will 'upstart' work without having to reboot? Something is just whispering yes to me :)
If not, what other option would I have to 'respawn' my node server when it crashes?
Yes, upstart will restart your process without a reboot.
Also, you should look into forever.
PM2 is a Production process manager for Node.js app.
If your focus for automatic restart is an always running application, I suggest to use a process manager. Process manager, in general, handles the node process(es if cluster enabled), and is responsible for the process/es execution. PM leans on the operative system: your node app and the OS are not so strinctly chained because the pm is in the middle.Final trick: put the process manager on upstart. Here is a complete performance improvement path to follow.
Using a shared server and not having root privileges, I can't download or install any of the previously mentioned libraries. What I am able to do is use a simple infinite bash loop to solve my issue. First, I created the file ./startup.sh in the base directory ($ vim startup.sh):
#!/bin/bash
while:
do
node ./dist/sophisticatedPrimate/server/main.js
done
Then I run it with:
$ bash startup.sh
and it works fine. There is a downside to this, which is that is doesn't have a graceful way to end the loop (at least not once I exit the server). What I ended up doing is simply finding the process with:
$ ps aux | grep startup.sh
Then killing it with
$ kill <process id>
example
$ kill 555555

Resources