Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Last active November 15, 2015 05:31
Show Gist options
  • Save bigdawggi/7f0d9276a1bf503906eb to your computer and use it in GitHub Desktop.
Save bigdawggi/7f0d9276a1bf503906eb to your computer and use it in GitHub Desktop.
Post Receive Hook for Git
#!/bin/sh
echo "********************"
echo "Post receive hook: Deploying Website"
echo "********************"
# Set up some vars
export GIT_REPO=/home/git/production/example.git
export GIT_WORK_TREE=/var/www/vhosts/example.com/staging
echo "*** Clearing out any staging dir ***"
sudo rm -rf $GIT_WORK_TREE
mkdir -p $GIT_WORK_TREE
# Removing this for some reason - @TODO see if it's actually necessary still
unset GIT_INDEX_FILE
echo "*** Checking out into staging location ***"
git checkout -f master
echo "*** Changing into that directory ***"
cd $GIT_WORK_TREE
echo "*** Utilizing the prod ENV ***"
mv .env.prod .env
echo "*** Kicking off Composer ***"
# composer update # DO NOT WANT TO UPDATE LIBS ON PRODUCTION - SHOULD ONLY USE `composer install` ON SERVER
composer install
echo "*** Running PHP Artisan Commands ***"
php artisan clear-compiled
php artisan optimize
echo "*** Giving proper permissions ***"
chmod -R a+w storage
chmod -R a+w bootstrap
echo "*** Linking in various assets ***"
ln -s /var/www/vhosts/example.com/phpMemcachedAdmin public/pma
ln -s /var/www/vhosts/example.com/crons/clymb/theclymb.json public/theclymb.json
echo "*** Removing any old backups ***"
cd ..
sudo rm -rf old.bup
echo "*** Backing up old site ***"
mv current old.bup
echo "*** Swapping Webroots ***"
mv staging current
echo "*** Swapping Webroots ***"
mv staging current
echo "*** Kill old queue - let supervisor start it back up again"
sudo pkill -f "php artisan queue:listen"
echo "*** Clearing page cache ***"
echo 'flush_all' | nc localhost 11211
echo "*** HEY, JUST WANTED TO TELL YOU - YOU ROCK! ***"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment