I learn meteorjs and I have a small remote VPS.
I want:
Here is what I do:
description "meteor app server"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
pre-start script
set -e
rm -f /path/to/your/app/.meteor/local/db/mongod.lock
end script
exec /bin/su - ec2-user -c '/path/to/your/app/meteor_server.sh'
post-stop script
pkill -f meteor
end script
The meteor_server.sh
script contains:
cd /path/to/your/app/; meteor run -p 3000 --production
Make sure to chmod +x
the meteor_server.sh
script and change the path to your app in the 3 locations. The script also kills all meteor tasks when it is stopped so it works for running a single meteor app only on your server. I got a meteor app running quickly this way using nginx but node seems to consume a lot of memory.
This is my meteorjs.conf file - works fine. I had all described issues before, but this variant fix them. Hope it helps somebody :)
All EXPORT
variables I got by printenv
# meteorjs - meteorjs job file
description "MeteorJS"
author "Alex Babichev"
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
chdir /home/dev/www/test
script
export MONGO_URL=mongodb://localhost:27017/meteor
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PWD=/home/sputnik
export NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
export HOME=/home/sputnik
echo "---- start ----"
cd /home/dev/www/test
exec mrt
end script
You should use Ubuntu way, which is Upstart:
http://upstart.ubuntu.com/ http://manpages.ubuntu.com/manpages/lucid/man5/init.5.html
How to define daemon job:
http://newcome.wordpress.com/2012/02/26/running-programs-as-linux-daemons-using-upstart/
Hope it helps :)
Your upstart file would be more or less:
# meteorjs - meteorjs job file
description "MeteorJS"
author "Igor S"
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
# Run before process
pre-start script
cd PATH_TO_METEOR_APP
echo ""
end script
# Start the process
exec meteor run -p 80 --help -- production