Mettre en place l'infrastructure
Mise en place de la machine
$ apt-get install neovim screen sqlite3 curl
$ vim .bashrc
# décommenter les alias utiles
export TERM="xterm-256color"
export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
$ mkdir .ssh
$ vim .ssh/authorized_keys
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBESZFif9+cWjdUtITPVW7xJ+ys/GXanpdBayp9eghah
Installation de Listsem
À faire : Documenter le lancement de la commande de rappels.
Listsem est constitué de plusieurs processus :
- un serveur web, qui répond aux requêtes HTTP ;
- un projectioniste, qui s'assure que les projectieurs soient lancés ;
- des projecteurs, pour analyser les évènements qui se produisent (demande déposée…) ;
- un composant de notification, qui envoie les notifications par courriels.
$ apt-get install python3-venv supervisor nginx mariadb-server
$ mysql_secure_installation
$ # créer un utilisateur et une base de données pour listsém
# CREATE DATABASE listsem CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
# CREATE USER listsem IDENTIFIED BY "abcd0987";
# GRANT ALL PRIVILEGES ON listsem.* TO listsem@'%';
$ python3 -m venv /var/www/listsem
$ cd /root
$ mkdir data logs
$ vim supervisor.ini
# voir ci-dessous
$ vim envfile.txt
# voir ci-dessous
$ source envfile.txt
$ . /var/www/listsem/bin/activate
(listsem) $ pip install listsem-0.1.0a0-py3-none-any.whl gunicorn pymysql [sendria]
(listsem) $ listsem bd initialiser
(listsem) $ listsem projecteurs amorcer
(listsem) $ listsem projecteurs statut
(listsem) $ listsem importer formations 2021-2022
(listsem) $ listsem importer seminaires 2021-2022 [--jauge 50]
(listsem) $ deactivate
# Pour que le serveur web puisse accéder aux ressources web (CSS, JS, …)
$ chown -R www-data:www-data /var/www/listsem
$ supervisord -c supervisor.ini
Il faut quotidiennenent envoyer les rappels nécessaires aux superviseurs :
Cela devrait être automatisé dans un CRON.
Les variables d'environnement à exporter (via par exemple un fichier envfile.txt
)
avant de lancer les commandes listsem
:
export MYSQL_DSN="mysql+pymysql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>"
export LISTSEM_EVENT_STORE_DSN="${MYSQL_DSN}",
export LISTSEM_PROJECTIONS_DSN="${MYSQL_DSN}",
export LISTSEM_DATA_DSN="${MYSQL_DSN}",
export LISTSEM_NEOBAB_URL="http://enseignements.ehess.fr/",
export LISTSEM_SMTP_HOST="localhost",
export LISTSEM_SMTP_PORT="1025",
export LISTSEM_SMTP_FROM="ne-pas-repondre@ehess.fr",
export LISTSEM_SMTP_NOREPLY="ne-pas-repondre@ehess.fr",
Le fichier de configuration de Supervisor (supervisor.ini
) :
[supervisord]
nodaemon=true
loglevel=info
identifier=supervisor
strip_ansi=false
redirect_stderr=false
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
stderr_events_enabled=false
environment=
LISTSEM_LOCALE="fr_FR.UTF-8",
LISTSEM_SECRET_KEY="12345",
LISTSEM_EVENT_STORE_DSN="mysql+pymysql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>",
LISTSEM_PROJECTIONS_DSN="mysql+pymysql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>",
LISTSEM_DATA_DSN="mysql+pymysql://<USER>:<PASSWORD>@<HOST>:<PORT>/<DATABASE>",
# LISTSEM_CAS_SERVER="https://cas.ehess.fr",
LISTSEM_CAS_LOGIN_ROUTE="/casv3",
LISTSEM_CAS_LOGOUT_ROUTE="/casv3/logout",
LISTSEM_CAS_VALIDATE_ROUTE="/casv3/serviceValidate",
LISTSEM_CAS_AFTER_LOGOUT="http://localhost:3000/auth/deconnexion",
# LISTSEM_SENTRY_URL="http://617d3bdc155f4717b604a7bd78084169@localhost:9000/2",
[program:webapp]
command=/var/www/listsem/bin/gunicorn --access-logfile="-" -w 4 -b 127.0.0.1:3000 "listsem.entry_points.wsgi:app()"
stdout_logfile=logs/webapp.log
stderr_logfile=logs/webapp.err.log
[program:projecteurs-projections]
command=listsem --verbose projecteurs demarrer --interval 1s --tous-sauf notifications,listes_diffusion
stdout_logfile=logs/projecteurs-projections.log
stderr_logfile=logs/projecteurs-projections.err.log
[program:projecteurs-autres]
command=listsem --verbose projecteurs demarrer --interval 1m --uniquement notifications,listes_diffusion
stdout_logfile=logs/projecteurs-autres.log
stderr_logfile=logs/projecteurs-autres.err.log
[program:mail-trap]
command=/var/www/listsem/bin/sendria --db mails.sqlite --smtp-port %(ENV_LISTSEM_SMTP_PORT)s
stdout_logfile=logs/mail_trap.log
stderr_logfile=logs/mail_trap.err.log
Le fichier de configuration d'Apache :
Le fichier de configuration NGINX (/etc/nginx/sites-enabled/listsem
) :
server {
listen 80;
access_log /var/log/nginx/listsem.log;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
location /ressources {
alias /var/www/listsem/lib/python3.9/site-packages/listsem/infrastructure/flask/static;
}
}
server {
listen 8080;
access_log /var/log/nginx/listsem.log;
location / {
proxy_pass http://localhost:1080;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
}
location /ws {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:1080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}