Skip to content

Instantly share code, notes, and snippets.

@wamburu wamburu/
Created Feb 2, 2017

What would you like to do?
Automatically Update site While spinning
info() { echo "INFO: $1"; }
die() { echo "ERROR: $1. Aborting!"; exit 1; }
SRC_DIR=$SRC_ROOT/{{ proj_name }}
# 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
# deploy app code
if [ -d "$SRC_DIR" ]; then
info "Updating source code."
git pull origin master
npm update
info "Installing source code."
mkdir -p $SRC_ROOT
{% if app_token %}
git clone https://{{ app_token }}{{ user_name }}/{{ proj_name }}.git $SRC_DIR
{% else %}
git clone{{ user_name }}/{{ proj_name }}.git $SRC_DIR
{% endif %}
npm install
# 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 "{{ 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
You can’t perform that action at this time.