kpsul/provisioning/bootstrap.sh

75 lines
2.4 KiB
Bash
Raw Permalink Normal View History

#!/bin/sh
# Stop if an error is encountered
set -e
# Configuration de la base de données. Le mot de passe est constant car c'est
# pour une installation de dév locale qui ne sera accessible que depuis la
# machine virtuelle.
DBUSER="cof_gestion"
DBNAME="cof_gestion"
DBPASSWD="4KZt3nGPLVeWSvtBZPSM3fSzXpzEU4"
# Installation de paquets utiles
apt-get update && apt-get upgrade -y
2017-08-09 23:07:49 +02:00
apt-get install -y python3-pip python3-dev python3-venv libpq-dev postgresql \
postgresql-contrib libjpeg-dev nginx git redis-server
2017-08-09 23:07:49 +02:00
# Postgresql
sudo -u postgres createdb $DBNAME
sudo -u postgres createuser -SdR $DBUSER
sudo -u postgres psql -c "ALTER USER $DBUSER WITH PASSWORD '$DBPASSWD';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DBNAME TO $DBUSER;"
2017-08-09 23:07:49 +02:00
# Redis
REDIS_PASSWD="dummy"
redis-cli CONFIG SET requirepass $REDIS_PASSWD
redis-cli -a $REDIS_PASSWD CONFIG REWRITE
# Contenu statique
mkdir -p /srv/gestiocof/media
mkdir -p /srv/gestiocof/static
2017-08-09 23:07:49 +02:00
chown -R ubuntu:www-data /srv/gestiocof
# Nginx
ln -s -f /vagrant/provisioning/nginx.conf /etc/nginx/sites-enabled/gestiocof.conf
rm -f /etc/nginx/sites-enabled/default
systemctl reload nginx
# Environnement virtuel python
sudo -H -u ubuntu python3 -m venv ~ubuntu/venv
sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -U pip
sudo -H -u ubuntu ~ubuntu/venv/bin/pip install -r /vagrant/requirements-devel.txt
# Préparation de Django
cd /vagrant
ln -s -f secret_example.py cof/settings/secret.py
2017-08-12 00:56:02 +02:00
sudo -H -u ubuntu \
DJANGO_SETTINGS_MODULE='cof.settings.dev' \
bash -c ". ~/venv/bin/activate && bash provisioning/prepare_django.sh"
/home/ubuntu/venv/bin/python manage.py collectstatic --noinput --settings cof.settings.dev
# Installation du cron pour les mails de rappels
sudo -H -u ubuntu crontab provisioning/cron.dev
2017-08-09 23:07:49 +02:00
# Daphne + runworker
cp /vagrant/provisioning/daphne.service /etc/systemd/system/daphne.service
cp /vagrant/provisioning/worker.service /etc/systemd/system/worker.service
systemctl enable daphne.service
systemctl enable worker.service
systemctl start daphne.service
systemctl start worker.service
# Mise en place du .bash_profile pour tout configurer lors du `vagrant ssh`
cat >> ~ubuntu/.bashrc <<EOF
# On utilise la version de développement de GestioCOF
export DJANGO_SETTINGS_MODULE='cof.settings.dev'
2016-11-06 15:39:50 +01:00
# Charge le virtualenv
source ~/venv/bin/activate
# On va dans /vagrant où se trouve le code de gestioCOF
cd /vagrant
EOF