Open dennisa opened 8 years ago
I am experiencing the same problem in AWS linux.
echo \$! > $PID_FILE"
its just echoing the pid created from the command to a pid file. I'm not sure why it would be wrong. Might want to ask in #bash on freenode.
If you replace get_pid()
with the following:
get_pid() {
echo "$(ps aux | grep node | awk 'NR==1{print $2}')"
}
Each command works perfectly.
That is not safe. There could be other node processes other than the one in the pid file that you don't want to kill. If you can give me a simple command that produces the wrong pid using (<cmd> ) &; echo $!
i'll ask the bash guys in irc
ah, that's of course correct. Thanks for checking into that. So, the following produces the correct pid:
# watch 'ls -lrat' & echo $!
[3] 7694
root 7694 0.0 0.3 116128 4044 pts/2 T 08:26 0:00 watch ls -lrat
I'm not sure whats going on here.
so it created the pid as 7694 and that's what you're seeing in the ps -ef output.
also i'm wondering if you have any forks/clustering or suexec commands in your app.
well ps aux | grep ls
, but yes.
I don't use this script anymore but its become popular. can you tell me what your settings are for the environment variables at the top of the script? I can try to reproduce.
Also, test your startup with a simple do { console.log('test') } while (true);
in your app.js. Just to rule out your app isn't causing the issue.
I'm actually having this problem on CentOS 6 and Amazon Linux. it appears that the PID being stored is not that of node, but the parent bash process that is spun off when the script starts node. Killing this bash process seems to leave the node app running.
In order to reliably kill off the node child, pkill can be used, which will kill children to a given process ID. I've sent a pull request for the change.
Hi! It's a problem of operator priority order.
If you do A && B & echo $!
, you're getting the PID of the process A && B
.
The init init script does:
cd $APP_DIR && node $APP & echo $! > $PID
So the PID belongs to the bash
process performing the cd and node. To solve, just put the command between parentheses:
cd $APP_DIR && (node $APP & echo $! > $PID)
This was fixed in #50 #51 @dennisa
Hi,
I was wondering if you could help me out but I'm using your script but the generate pid always seems to get 2 number below the real process id of the running node app.
i.e. the reported pid is 20195 but when I tried to do a ps -aux | grep node, i could see the pid is actually 20197.
Do you know what might be going wrong