Create a gist now

Instantly share code, notes, and snippets.

@d5 /bootstrap.sh
Last active Feb 18, 2016

What would you like to do?
#!/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