Hi!
I was just down this same road. This is the upstart script that I ended up
with on my system (RH 6.1):
#!upstart
description "NodeApp - node.js HTTP-server"
author "Me"
# One example said that it's safer to start after mounts
#start on startup
start on started mountall
stop on shutdown
# respawn
respawn
# If the process is respawed more than COUNT times within an interval of
INTERVAL seconds the process will be stopped and not restarted
# respawn limit COUNT INTERVAL
respawn limit 10 2
# settings
env APP_NAME="NodeApp"
env APP_DIR="/home/nodeuser/dev/NodeApp"
env APP_FILE="NodeApp.js"
env RUN_AS="nodeuser"
# This is setting for the app...
env NODE_ENV="production"
script
export HOME="/home/${RUN_AS}/"
export NODE_ENV
echo $$ > /var/run/${APP_NAME}.pid
# sudo doesn't work on redhat 6.1
# exec sudo -u nodeuser /usr/local/bin/node
/home/nodeuser/dev/NodeApp.js >> /var/log/NodeApp.log 2>&1
exec su --session-command="/usr/local/bin/node ${APP_DIR}/${APP_FILE}"
>> /var/log/${APP_NAME}.log 2>&1 ${RUN_AS}
# root works also - but you don't want to run as root, right
# echo $$ > /var/run/NodeApp.pid
# export HOME="/root"
# exec /usr/local/bin/node /home/nodeuser/dev/NodeApp/NodeApp.js >>
/var/log/NodeApp.log 2>&1
end script
pre-start script
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Starting" >>
/var/log/${APP_NAME}.log
end script
pre-stop script
rm /var/run/${APP_NAME}.pid
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Stopping" >>
/var/log/${APP_NAME}.log
end script
Start with 'sudo start NodeApp' and stop with sudo stop... When you develop
this, do not enable respawn until it works otherwise. You can run it as
root if you want (if you need port 80), but otherwise, I think it's much
better to run as some other user. Yes, it could be cleaner, but I'll hope
you get the important points.
On Mon, Mar 12, 2012 at 5:02 PM, Flavio Del Bianco <
[email protected]> wrote:
> Hi, I'm learning nodejs and I had a doubt in how I keep alive a
> webserver without running it everytime like $ node myserver.js? and
> how it can connect alone every time the server get on like it does
> apache.
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
--
HG.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en