Skip to content

Instantly share code, notes, and snippets.

@lechup
Last active March 17, 2017 12:53
Show Gist options
  • Save lechup/e2557dceb4f1527e2c40c260fd3f0dda to your computer and use it in GitHub Desktop.
Save lechup/e2557dceb4f1527e2c40c260fd3f0dda to your computer and use it in GitHub Desktop.
Simple deploy script, should be run from production, it uses screen to maintain connection in case of ssh failure + writes log to deploy.log and deploy.err.log
#!/bin/bash
# cleaning up sudo su "Cannot open your terminal" error
# http://serverfault.com/a/620149/63835
function screen() {
exec /usr/bin/script -q -c "/usr/bin/screen ${*}" /dev/null
}
# run inside screen
# http://unix.stackexchange.com/a/162150/53005
if [ -z "$STY" ]
then
screen -m -S smogly.deploy /bin/bash "$0" > >(tee deploy.log) 2> >(tee deploy.err.log >&2)
exit 0
fi
cd /home/smogly/EnviroMonitorWeb
echo "pulling from git..."
git reset --hard
git pull
echo "install pip dependencies..."
pip install -r docker/web/requirements.txt
echo "collect statics ..."
./manage.py collectstatic --noinput
echo "migrate database ..."
./manage.py migrate
echo "restart nginx and gunicorn ..."
supervisorctl pid smogly-gunicorn | xargs kill -HUP
sudo reload-nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment