Skip to content

Instantly share code, notes, and snippets.

@zmpeg
Created March 3, 2015 04:05
Show Gist options
  • Save zmpeg/198bbd6e9eed2bb3ea3e to your computer and use it in GitHub Desktop.
Save zmpeg/198bbd6e9eed2bb3ea3e to your computer and use it in GitHub Desktop.
Git post-receive deploy hook for simple node apps using screen. Place this in a file in a bare repo under hooks/post-receive.
#!/bin/bash
DEPLOY_DIR="$HOME/apps/my-app/"
SCREEN_NAME="my-app"
echo "Deploying"
GIT_WORK_TREE="${DEPLOY_DIR}" git checkout -f master
echo "Loading nvm, node, npm"
export NVM_DIR="/home/deploy/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
echo "Running \`npm install\`"
cd $DEPLOY_DIR
npm install
echo "Stopping running app"
screen -X -S $SCREEN_NAME quit
echo "Starting app again"
screen -d -m -S $SCREEN_NAME ./app.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment