Skip to content

Instantly share code, notes, and snippets.

@ernstki
Created July 14, 2014 04:51
Show Gist options
  • Save ernstki/e43ffbd1b1929bf829c0 to your computer and use it in GitHub Desktop.
Save ernstki/e43ffbd1b1929bf829c0 to your computer and use it in GitHub Desktop.
Sample Git post-receive hook for a Rails/mod_rails app
#!/bin/bash
set -x
export GIT_WORK_TREE=/var/www/tm
export RAILS_ENV=mod_rails
if [ ! -d "$GIT_WORK_TREE" ]; then
echo "ACK! The specified working tree ($GIT_WORK_TREE) doesn't exist. Quitting." >&2
exit 3
fi
git checkout -f dev
# Tell Passenger to restart the app
touch $GIT_WORK_TREE/tmp/restart.txt
# Is it safe to run db:migrate on a running production app? Hope so.
cd /var/www/tm
rake db:migrate
# Example post-receive hook using a 'manifest' file to check out only
# specified files.
# -------------------------------------------------------------------
# echo "Fetching the manifest"
# MANIFEST="$GIT_WORK_TREE/manifest"
# git checkout -f master manifest
# if [ $? -ne 0 -o ! -f "$MANIFEST" ]; then
# echo "ACK! Could not check out the manifest file from MASTER. Quitting." >&2
# exit 2
# fi
#
# # Otherwise:
# while read file; do
# # Skip comments
# if [ ${file:0:1}x = "#x" ]; then
# continue
# fi
# set -x
# git checkout -f master "$file"
# set +x
# done < "$MANIFEST"
#
# rm -f "$MANIFEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment