Last active
December 14, 2015 13:38
-
-
Save ivarprudnikov/5094624 to your computer and use it in GitHub Desktop.
upstart node.conf for launching node app with npm and installing dependencies on amazon ubuntu ami
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/init/node.conf | |
description 'node.js app production' | |
author 'ivarprudnikov.com' | |
env NAME=app-name | |
env ENV=production | |
env PORT=8080 | |
env LOG_FILE=/var/log/app-name.log | |
env USER=ubuntu | |
env NPM_BIN=/usr/bin/npm | |
env APP_LOCATION=/var/www/thisismyapp | |
env REPO=https://github.com/aprudnikovas/youtube-hoover.git | |
env DB_URI=mongodb://127.0.0.1:27017/youtube-hoover | |
start on started networking | |
stop on stopping networking | |
# Respawn in case of a crash, with default parameters | |
respawn | |
pre-start script | |
touch $LOG_FILE | |
chown $USER:$USER $LOG_FILE | |
sudo mkdir -p $APP_LOCATION | |
girror $REPO $APP_LOCATION | |
echo ">>>>> Installing $NAME dependencies" >> $LOG_FILE | |
cd $APP_LOCATION | |
sudo $NPM_BIN install >> $LOG_FILE 2>&1 | |
sudo chown -R $USER:$USER $APP_LOCATION | |
end script | |
script | |
export NODE_ENV=$ENV | |
export PORT=$PORT | |
export DB_URI=$DB_URI | |
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports $PORT | |
cd $APP_LOCATION | |
exec su -s /bin/sh -c 'exec "$0" "$@"' $USER -- $NPM_BIN start >> $LOG_FILE 2>&1 | |
end script | |
post-start script | |
echo ">>>>> App $NAME started" >> $LOG_FILE | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment