Created
November 17, 2012 15:38
-
-
Save lusentis/4096858 to your computer and use it in GitHub Desktop.
Git hooks and scripts for production deployment (Python only at the moment)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add this line: | |
[receive] | |
denyCurrentBranch = warn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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