Skip to content

Instantly share code, notes, and snippets.

@arvsr1988
Created September 22, 2016 06:44
Show Gist options
  • Save arvsr1988/91faeda0c214b47a4c547e9dc95f241f to your computer and use it in GitHub Desktop.
Save arvsr1988/91faeda0c214b47a4c547e9dc95f241f to your computer and use it in GitHub Desktop.
deploying a node app using a CI system to a new directory.
#bin/bash
CURRENT_DATE=`date +%s`
echo "current date is $CURRENT_DATE"
DEPLOYMENT_DIR='{deployment directory}'
CURRENT_DEPLOYMENT_DIR=$DEPLOYMENT_DIR$CURRENT_DATE
ARTIFACT_ZIP_LOCATION=~/tmp/
echo "current deployment dir $CURRENT_DEPLOYMENT_DIR"
PM2_PROCESS_NAME='{process name}'
mkdir -p $CURRENT_DEPLOYMENT_DIR
cp $ARTIFACT_ZIP_LOCATION/web.tar.gz $CURRENT_DEPLOYMENT_DIR
cd $CURRENT_DEPLOYMENT_DIR
gzip -d web.tar.gz
tar -xf web.tar
pm2 stop $PM2_PROCESS_NAME
pm2 delete $PM2_PROCESS_NAME
rm $DEPLOYMENT_DIR/current && ln -s $CURRENT_DEPLOYMENT_DIR $DEPLOYMENT_DIR/current
NODE_ENV=production pm2 start server.js --name="$PM2_PROCESS_NAME"
rm web.tar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment