Skip to content

Instantly share code, notes, and snippets.

@lusentis
Created November 17, 2012 15:38
Show Gist options
  • Save lusentis/4096858 to your computer and use it in GitHub Desktop.
Save lusentis/4096858 to your computer and use it in GitHub Desktop.
Git hooks and scripts for production deployment (Python only at the moment)
# add this line:
[receive]
denyCurrentBranch = warn
#!/bin/bash
#
# save this file in .git/hooks/post-receive
#
set -e
VENV=$(pwd)/../../.venv
echo -e "\n====> Working dir is" $(pwd)
GIT_DIR='.git'
cd ..
echo -e "\n====> Updating repo..."
umask 002 && git reset --hard
echo -e "\n====> Creating virtualenv in $VENV..."
#rm -Rf .venv
if [ ! -d $VENV ]
then
virtualenv --system-site-packages $VENV
fi
#PATH=$VENV/bin:$PATH
source $VENV/bin/activate
$VENV/bin/pip install -r requirements.txt
echo -e "\n====> Stopping app..."
kill -SIGQUIT $(cat ../mon.pid) || true
echo -e "\n====> Starting app..."
bash Runfile.sh
echo -e "\n====> App deployed!\n"
exit 0
#!/bin/bash
## use this line to run on startup via rc.local
# su user -c "cd ~/app && bash /home/user/app/Runfile.sh"
##
PORT=8000
DIR=$(pwd)/..
PATH=$DIR/.venv/bin:$PATH
CMD="source $DIR/env.sh && PYTHONPATH=$DIR:\$PYTHONPATH $DIR/.venv/bin/gunicorn_django -b 127.0.0.1:$PORT web"
echo "*** App is starting. Logfile is $DIR/app.log ***"
mon --log $DIR/app.log --pidfile $DIR/app.pid --mon-pidfile $DIR/mon.pid --sleep 5 --attempts 10 --daemonize "$CMD"
sleep 5
tail -n 10 $DIR/app.log
echo "*** Completed. App running with PID" $(cat $DIR/app.pid) "***"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment