Last active
September 12, 2017 00:19
-
-
Save andrewmartin/78f28c14be0cfe85d145b34dd836aa62 to your computer and use it in GitHub Desktop.
post-receive hook for pm2
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
#!/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