I am using upstart to start a NodeJS process which is using NVM (node version manager).
The upstart command is like this:
description "Service to start node app"
author "Barry Steyn"
setuid devuser
setgid devuser
env DIR=/home/devuser/nodejs/authentication
script
chdir $DIR
exec bash -c 'source /home/devuser/nvm/nvm.sh && node app'
end script
respawn
This starts node fine, but when I do a ps wax | grep node
, I get these two processes:
4284 ? Ss 0:00 bash -c source /home/devuser/nvm/nvm.sh && node app
4316 ? Sl 1:09 node app
Why do I get two processes? Is this in anyway less efficient?
The first process is the instance of bash that started node.js. The second process is the actual node.js process.
The bash process is using a few resources (mostly memory), but is just sitting around waiting on node.js to exit.
I believe you can get rid of the extra bash by doing this:
Replace:
exec bash -c 'source /home/devuser/nvm/nvm.sh && node app'
With:
exec bash -c 'source /home/devuser/nvm/nvm.sh && exec node app'
This gets the bash process to exec node.js without using a fork first. Mostly that means it won't wait around for node.js to exit.