Created
February 18, 2016 15:54
-
-
Save BarronKane/75825dbc8778ef36a91b to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
info() { echo "INFO: $1"; } | |
die() { echo "ERROR: $1. Aborting!"; exit 1; } | |
SRC_ROOT=/usr/local/src | |
SRC_DIR=$SRC_ROOT/{{ proj_name }} | |
STATIC_DIR=/usr/share/nginx/html | |
# stop node apps if they're running | |
info 'Stopping running applications and Nginx' | |
forever stopall 2> /dev/null | |
service nginx stop 2> /dev/null | |
# install dependencies | |
info 'Updating yum repos and install dependencies.' | |
yum update -y | |
yum install -y --enablerepo=epel git nginx npm || die "failed to install dependencies." | |
# install forever if not installed | |
if ! type forever > /dev/null 2>&1; then | |
info 'Installing "forever" node module.' | |
npm install forever -g | |
fi | |
# deploy app code | |
if [ -d "$SRC_DIR" ]; then | |
info "Updating source code." | |
cd $SRC_DIR | |
git pull origin master | |
npm update | |
else | |
info "Installing source code." | |
mkdir -p $SRC_ROOT | |
{% if app_token %} | |
git clone https://{{ app_token }}:@github.com/{{ user_name }}/{{ proj_name }}.git $SRC_DIR | |
{% else %} | |
git clone https://github.com/{{ user_name }}/{{ proj_name }}.git $SRC_DIR | |
{% endif %} | |
cd $SRC_DIR | |
npm install | |
fi | |
# configure and start nodes | |
{% for p in split(ports, ",") %} | |
mkdir -p /var/log/nodes/{{ p.value }} | |
forever start -a \ | |
-l /var/log/nodes/{{ p.value }}/fv.log \ | |
-o /var/log/nodes/{{ p.value }}/out.log \ | |
-e /var/log/nodes/{{ p.value }}/err.log \ | |
--minUptime=10000 --spinSleepTime=1000 \ | |
-m {{ max_retry }} \ | |
app.js {{ p.value }} | |
{% endfor %} | |
# setup and start reverse proxy | |
info "Starting up Nginx." | |
curl -L "https://gist.sh/8252838?ports={{ ports }}" > /etc/nginx/nginx.conf | |
chkconfig nginx on | |
service nginx start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment