Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active August 29, 2015 14:02
Show Gist options
  • Save bodokaiser/600a2dd77ee31cfcb2af to your computer and use it in GitHub Desktop.
Save bodokaiser/600a2dd77ee31cfcb2af to your computer and use it in GitHub Desktop.
git post receive hook for nvm environments
#!/bin/bash
source $HOME/.bash_profile
set -u
set -e
# directory name
NAME=$(basename $(pwd) .git)
# working tree name
WORK=/srv/node/$NAME
# name of logs to share
LOGS=/var/log/node-$NAME.log
# copies file to working tree
echo -e "\n--> Updating $NAME"
mkdir -p $WORK && GIT_WORK_TREE=$WORK git checkout -f
# installs missing packages
echo -e "\n--> Installing packages"
cd $WORK && npm install
# outputs logs
echo -e "\n--> Service will be restarted"
service "node-$NAME" restart && cat $LOGS | tail -20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment