Last active
August 29, 2015 14:23
-
-
Save kuno/6c92b9350cdc2fc43c04 to your computer and use it in GitHub Desktop.
The mm-web deploy script that working for local development
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 | |
# Update nginx config | |
sed -e "s#MEDIA_ROOT#$MEDIA_ROOT#g" \ | |
-e "s#STATIC_ROOT#$STATIC_ROOT#g" \ | |
/etc/nginx/conf.d/default.conf.tpl > /etc/nginx/conf.d/default.conf | |
install_requirements() { | |
for requirement in requirement* | |
do | |
if [ -e "$requirement" ]; then | |
echo "Installing requirement file: $requirement" | |
pip install -r $requirement | |
fi | |
done | |
} | |
# Deploy myanmar | |
SRC=/data/lib | |
cd $SRC | |
for project in * | |
do | |
if [ -d "$SRC/$project" ]; then | |
if [ -e "$SRC/$project/setup.py" ]; then | |
cd /tmp | |
rm -rf $project | |
cp -a "$SRC/$project" $project | |
cd $project | |
pkg_name=$(grep 'name=' setup.py | cut -f2 -d"'") | |
pip uninstall -y $pkg_name | |
pip install . | |
install_requirements | |
else | |
echo "Project $project is not installable (missing setup.py) - Skipping" | |
fi | |
else | |
echo "Project $project is not a folder - Skipping" | |
fi | |
done | |
# Create / sync the database for the dataimport | |
cd /data/import_djangoproject | |
install_requirements | |
# Ensure the DB is ready and reachable | |
echo "Wait until DB is ready" | |
while [ 1 ]; do | |
ping -c 1 "$POSTGRES_HOST" > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
echo "DB is resolvable - wait a bit to ensure postgres starts..." | |
sleep 5 | |
break | |
else | |
echo -n . | |
sleep 1 | |
fi | |
done | |
cd /data/ui | |
install_requirements | |
PYTHONPATH=. python manage.py migrate | |
#if [ "$DJANGO_MODULES_SETTINGS" == 'settings.ui' -o "$DJANGO_MODULES_SETTINGS" == 'settings.dev' ]; then | |
echo "Installing fixtures" | |
PYTHONPATH=. python manage.py installfixtures --noinput | |
echo "Installing mydevinstall" | |
PYTHONPATH=. python manage.py mydevinstall | |
#fi | |
PYTHONPATH=. python manage.py mysearchinstall | |
PYTHONPATH=. python manage.py migratepermissions | |
# Create user if not existing | |
echo " | |
from django.contrib.auth.models import User | |
try: | |
User.objects.get(username='admin') | |
except User.DoesNotExist: | |
User.objects.create_superuser('admin', 'admin@example.com', 'password') | |
" | PYTHONPATH=. python manage.py shell | |
# If supervisord is running - restart some services | |
/usr/local/bin/supervisorctl status > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
/usr/local/bin/supervisorctl restart ui | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment