Skip to content

Instantly share code, notes, and snippets.

@andrewmartin
Last active September 12, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewmartin/78f28c14be0cfe85d145b34dd836aa62 to your computer and use it in GitHub Desktop.
Save andrewmartin/78f28c14be0cfe85d145b34dd836aa62 to your computer and use it in GitHub Desktop.
post-receive hook for pm2
#!/usr/bin/env bash
# start your app first; pm2 start ./build/server.js --name app-name
# then, place in repo.git/hooks/post-receive
# and set permissions:
# chmod +x hooks/post-receive
set -u
set -e
export GIT_WORK_TREE="/var/apps/app-name"
export NODE_ENV="PRODUCTION"
echo "--> Changing to work directory...$GIT_WORK_TREE"
echo "--> Checking out..."
git checkout -f
# Install dependencies
echo "--> Installing libraries..."
cd "$GIT_WORK_TREE"
npm install --production
npm prune --production
pm2 restart app-name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment