mirror of
				https://gitlab.crans.org/mediatek/med.git
				synced 2025-10-31 21:04:32 +01:00 
			
		
		
		
	Add uwsgi configuration
This commit is contained in:
		
							
								
								
									
										38
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								README.md
									
									
									
									
									
								
							| @@ -11,22 +11,48 @@ Elle permet de gérer les medias, bd, jeux, emprunts, ainsi que les adhérents d | |||||||
|  |  | ||||||
| Ce projet est sous la licence GNU public license v3.0. | Ce projet est sous la licence GNU public license v3.0. | ||||||
|  |  | ||||||
| ## Développement | ## Installation | ||||||
|  |  | ||||||
| Après avoir installé un environnement Django, | ### Développement | ||||||
|  |  | ||||||
|  | On peut soit développer avec Docker, soit utiliser un VirtualEnv. | ||||||
|  |  | ||||||
|  | Dans le cas du VirtualEnv, | ||||||
|  |  | ||||||
| ```bash | ```bash | ||||||
|  | python3 -m venv venv | ||||||
|  | . venv/bin/activate | ||||||
|  | pip install -r requirements.txt | ||||||
| ./manage.py migrate | ./manage.py migrate | ||||||
| ./manage.py collectstatic | ./manage.py collectstatic | ||||||
| ./manage.py runserver | ./manage.py runserver | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| ## Configuration d'une base MySQL | ### Production | ||||||
|  |  | ||||||
| Sur le serveur mysql ou postgresl, il est nécessaire de créer une base de donnée med, | Vous pouvez soit utiliser Docker, soit configurer manuellement le serveur. | ||||||
|  |  | ||||||
|  | #### Mise en place du projet sur Zamok | ||||||
|  |  | ||||||
|  | Pour mettre en place le projet sans droits root, | ||||||
|  | on va créer un socket uwsgi dans le répertoire personnel de l'utilisateur `club-med` | ||||||
|  | puis on va dire à Apache2 d'utiliser ce socket avec un `.htaccess`. | ||||||
|  |  | ||||||
|  | Pour cela on va imiter ce que fait l'image Docker, | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | python3 -m venv venv | ||||||
|  | . venv/bin/activate | ||||||
|  | pip install -r requirements.txt | ||||||
|  | ./entrypoint.sh | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | #### Configuration d'une base de données | ||||||
|  |  | ||||||
|  | Sur le serveur MySQL ou PostgreSQL, il est nécessaire de créer une base de donnée med, | ||||||
| ainsi qu'un user med et un mot de passe associé. | ainsi qu'un user med et un mot de passe associé. | ||||||
|  |  | ||||||
| Voici les étapes à éxecuter pour mysql : | Voici les étapes à executer pour MySQL : | ||||||
|  |  | ||||||
| ```SQL | ```SQL | ||||||
| CREATE DATABASE med; | CREATE DATABASE med; | ||||||
| @@ -35,7 +61,7 @@ GRANT ALL PRIVILEGES ON med.* TO 'med'@'localhost'; | |||||||
| FLUSH PRIVILEGES; | FLUSH PRIVILEGES; | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| Et pour postgresql : | Et pour PostgreSQL : | ||||||
|  |  | ||||||
| ```SQL | ```SQL | ||||||
| CREATE DATABASE med; | CREATE DATABASE med; | ||||||
|   | |||||||
| @@ -1,8 +1,25 @@ | |||||||
| #!/bin/bash | #!/bin/bash | ||||||
|  | # This will launch the Django project as a fastcgi socket | ||||||
|  | # then Apache or NGINX will be able to use that socket | ||||||
|  |  | ||||||
| python manage.py compilemessages | python manage.py compilemessages | ||||||
| python manage.py makemigrations | python manage.py makemigrations | ||||||
|  |  | ||||||
|  | # Wait for database | ||||||
| sleep 2 | sleep 2 | ||||||
|  |  | ||||||
| python manage.py migrate | python manage.py migrate | ||||||
|  |  | ||||||
| # TODO: use uwsgi in production | uwsgi --chdir="$(pwd)" \ | ||||||
| python manage.py runserver 0.0.0.0:8000 |     --module=med.wsgi:application \ | ||||||
|  |     --env DJANGO_SETTINGS_MODULE=med.settings \ | ||||||
|  |     --master \ | ||||||
|  |     --pidfile="$(pwd)/uwsgi.pid" \  # create a pidfile | ||||||
|  |     --socket="$(pwd)/uwsgi.sock" \ | ||||||
|  |     --processes=5 \ | ||||||
|  |     --chmod-socket=600 \ | ||||||
|  |     --harakiri=20 \  # respawn processes taking more than 20 seconds | ||||||
|  |     --max-requests=5000 \  # respawn processes after serving 5000 requests | ||||||
|  |     --vacuum \  # clean up when stopped | ||||||
|  |     --daemonize="$(pwd)/uwsgi.log" \ | ||||||
|  |     --protocol=fastcgi | ||||||
| @@ -9,4 +9,5 @@ python-stdnum==1.10 | |||||||
| djangorestframework==3.9.2 | djangorestframework==3.9.2 | ||||||
| pyyaml==3.13 | pyyaml==3.13 | ||||||
| coreapi==2.3.3 | coreapi==2.3.3 | ||||||
| psycopg2 | psycopg2==2.7.7 | ||||||
|  | uwsgi==2.0.18 | ||||||
		Reference in New Issue
	
	Block a user