From 2db49315089656f1b726ccbea743128684f24884 Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Wed, 19 Jun 2019 11:20:56 +0200 Subject: [PATCH] Gunicorn / uvicorn and 0-downtime upgrade --- defaults/main.yml | 1 + handlers/main.yml | 9 ++++++++- tasks/funkwhale.yml | 16 ++++++++++++++-- tasks/packages.yml | 1 + tasks/services.yml | 2 +- templates/env.j2 | 1 + 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index ba9f403..4619417 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,6 +15,7 @@ funkwhale_nginx_max_body_size: 100M funkwhale_redis_managed: true funkwhale_api_ip: 127.0.0.1 funkwhale_api_port: 5000 +funkwhale_web_workers: 1 funkwhale_protocol: https funkwhale_settings_module: config.settings.production funkwhale_env_vars: [] diff --git a/handlers/main.yml b/handlers/main.yml index d15f22d..f4b7666 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,9 +2,16 @@ - name: restart funkwhale become: true service: - name: funkwhale.target + name: "{{ funkwhale_systemd_service_name }}.target" state: restarted +- name: reload funkwhale + become: true + shell: | + systemctl kill -s HUP {{ funkwhale_systemd_service_name }}-server + systemctl kill -s HUP {{ funkwhale_systemd_service_name }}-worker + systemctl restart {{ funkwhale_systemd_service_name }}-beat + - name: reload nginx become: true service: diff --git a/tasks/funkwhale.yml b/tasks/funkwhale.yml index 0fc178b..7ccdeaa 100644 --- a/tasks/funkwhale.yml +++ b/tasks/funkwhale.yml @@ -76,7 +76,7 @@ dest: "{{ funkwhale_install_path }}" remote_src: true notify: - - restart funkwhale + - reload funkwhale - name: Download api files become: true @@ -86,7 +86,7 @@ dest: "{{ funkwhale_install_path }}" remote_src: true notify: - - restart funkwhale + - reload funkwhale - name: "Setup virtualenv" become: true @@ -103,6 +103,18 @@ requirements: "{{ funkwhale_install_path }}/api/requirements.txt" virtualenv: "{{ funkwhale_install_path }}/virtualenv" virtualenv_python: python3 + notify: + - reload funkwhale + +- name: "Install gunicorn/uvicorn" + become: true + become_user: "{{ funkwhale_username }}" + pip: + name: + - gunicorn + - uvicorn + virtualenv: "{{ funkwhale_install_path }}/virtualenv" + virtualenv_python: python3 notify: - restart funkwhale diff --git a/tasks/packages.yml b/tasks/packages.yml index 4286607..fc2d1b8 100644 --- a/tasks/packages.yml +++ b/tasks/packages.yml @@ -14,6 +14,7 @@ - "unzip" - "build-essential" - "ffmpeg" + - "make" - "libjpeg-dev" - "libmagic-dev" - "libpq-dev" diff --git a/tasks/services.yml b/tasks/services.yml index e1123d6..8d2a3c1 100644 --- a/tasks/services.yml +++ b/tasks/services.yml @@ -12,7 +12,7 @@ command: "{{ funkwhale_install_path }}/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO" - name: server description: Funkwhale application server - command: "{{ funkwhale_install_path }}/virtualenv/bin/daphne -b ${FUNKWHALE_API_IP} -p ${FUNKWHALE_API_PORT} config.asgi:application --proxy-headers" + command: "{{ funkwhale_install_path }}/virtualenv/bin/gunicorn config.asgi:application -w ${FUNKWHALE_WEB_WORKERS} -k uvicorn.workers.UvicornWorker -b ${FUNKWHALE_API_IP}:${FUNKWHALE_API_PORT}" - name: beat description: Funkwhale celery beat process command: "{{ funkwhale_install_path }}/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO" diff --git a/templates/env.j2 b/templates/env.j2 index 4ef1f91..587e63b 100644 --- a/templates/env.j2 +++ b/templates/env.j2 @@ -6,6 +6,7 @@ DJANGO_SECRET_KEY={{ django_secret_key }} FUNKWHALE_API_IP={{ funkwhale_api_ip }} FUNKWHALE_API_PORT={{ funkwhale_api_port }} +FUNKWHALE_WEB_WORKERS={{ funkwhale_web_workers }} REVERSE_PROXY_TYPE=nginx {% if funkwhale_database_managed %} -- GitLab