diff --git a/ansible/playbooks/deploy_app.yml b/ansible/playbooks/deploy_app.yml index 3fd9aeffd..ef7d6ccd7 100644 --- a/ansible/playbooks/deploy_app.yml +++ b/ansible/playbooks/deploy_app.yml @@ -119,21 +119,68 @@ tags: - static - - name: Reload gunicorn due to no git upstream changes - become: yes - block: - - name: Find gunicorn process - shell: "ps -C gunicorn fch -o pid | head -n 1" - register: psaux - - name: Reload gunicorn - command: "kill -HUP {{ psaux.stdout }}" - # Only restart if there were no changes to the git repo or the static tag was applied - when: not pulled.changed or "'static' in ansible_playbook_tag" - rescue: - - name: Restart Docker Container - command: "docker restart newsblur_web" - tags: - - static + - name: Run new Docker container with temporary name + docker_container: + name: "newsblur_web_new" + image: "newsblur/newsblur_web:latest" + pull: true + state: started + restart_policy: always + command: "gunicorn newsblur.wsgi:application --bind :8000 --workers 4" + hostname: "newsblur_web_new" + networks: + - name: newsblur-network + ports: + - "8001:8000" # Use different port for new instance + volumes: + - /srv/newsblur:/srv/newsblur + - /etc/nginx/sites-enabled:/etc/nginx/sites-enabled + - /etc/nginx/sites-available:/etc/nginx/sites-available + - /srv/secrets-newsblur:/srv/secrets-newsblur + + - name: Wait for new temp container to be healthy + uri: + url: "http://localhost:8001/api/health-check" # Add health check endpoint + status_code: 200 + validate_certs: no + register: result + retries: 10 + delay: 5 + until: result.status == 200 + + - name: Run new Docker container with original name + docker_container: + name: "newsblur_web" + image: "newsblur/newsblur_web:latest" + pull: true + state: started + restart_policy: always + command: "gunicorn newsblur.wsgi:application --bind :8000 --workers 4" + hostname: "newsblur_web" + networks: + - name: newsblur-network + ports: + - "8000:8000" + volumes: + - /srv/newsblur:/srv/newsblur + - /etc/nginx/sites-enabled:/etc/nginx/sites-enabled + - /etc/nginx/sites-available:/etc/nginx/sites-available + - /srv/secrets-newsblur:/srv/secrets-newsblur + + - name: Wait for new original container to be healthy + uri: + url: "http://localhost:8000/api/health-check" + status_code: 200 + validate_certs: no + register: result + retries: 10 + delay: 5 + until: result.status == 200 + + - name: Stop and remove temp Docker container + docker_container: + name: "newsblur_web_new" + state: absent - name: Start Consul become: yes diff --git a/ansible/roles/celery_task/tasks/main.yml b/ansible/roles/celery_task/tasks/main.yml index e65da5438..ea1098606 100644 --- a/ansible/roles/celery_task/tasks/main.yml +++ b/ansible/roles/celery_task/tasks/main.yml @@ -54,7 +54,7 @@ - /etc/hosts:/etc/hosts with_items: - container_name: "task-celery" - command: "celery worker -A newsblur_web --loglevel=INFO -Q new_feeds,push_feeds,update_feeds,search_indexer,discover_indexer" + command: "celery worker -A newsblur_web --loglevel=INFO -Q discover_indexer,search_indexer,new_feeds,push_feeds,update_feeds" when: "{{ inventory_hostname == 'htask-celery-10' }}" - container_name: "task-celery" command: "celery worker -A newsblur_web --loglevel=INFO -Q new_feeds,push_feeds,update_feeds,search_indexer" diff --git a/config/gunicorn_conf.py b/config/gunicorn_conf.py index b6f226127..4afef20f4 100644 --- a/config/gunicorn_conf.py +++ b/config/gunicorn_conf.py @@ -25,7 +25,6 @@ forwarded_allow_ips = "*" limit_request_line = 16000 limit_request_fields = 1000 worker_tmp_dir = "/dev/shm" -reload = True workers = max(int(math.floor(GIGS_OF_MEMORY * 2)), 3) diff --git a/docker/haproxy/haproxy.consul.cfg.j2 b/docker/haproxy/haproxy.consul.cfg.j2 index 01a7a5471..e4621eca1 100644 --- a/docker/haproxy/haproxy.consul.cfg.j2 +++ b/docker/haproxy/haproxy.consul.cfg.j2 @@ -183,6 +183,7 @@ backend staging default-server check inter 2000ms resolvers consul resolve-prefer ipv4 resolve-opts allow-dup-ip init-addr none {% for host in groups.staging %} server {{host}} {{host}}.node.nyc1.consul:8000 + server {{host}} {{host}}.node.nyc1.consul:8001 backup {% endfor %} backend blog diff --git a/docker/haproxy/haproxy.staging.cfg b/docker/haproxy/haproxy.staging.cfg index b075ada5f..44015489f 100644 --- a/docker/haproxy/haproxy.staging.cfg +++ b/docker/haproxy/haproxy.staging.cfg @@ -113,16 +113,19 @@ backend app_django_counts balance roundrobin option httpchk GET /_haproxychk server app_django 127.0.0.1:8000 check inter 3000ms + server app_django_backup 127.0.0.1:8001 check inter 3000ms backup backend app_django_refresh balance roundrobin option httpchk GET /_haproxychk server app_django 127.0.0.1:8000 check inter 3000ms + server app_django_backup 127.0.0.1:8001 check inter 3000ms backup backend app_django balance roundrobin option httpchk GET /_haproxychk server app_django 127.0.0.1:8000 check inter 3000ms + server app_django_backup 127.0.0.1:8001 check inter 3000ms backup backend maintenance option httpchk HEAD /maintenance diff --git a/newsblur_web/entrypoint.sh b/newsblur_web/entrypoint.sh index 732f43dec..ec6d252df 100755 --- a/newsblur_web/entrypoint.sh +++ b/newsblur_web/entrypoint.sh @@ -2,5 +2,5 @@ if [[ -z "${TEST}" && "${TEST}" = "True" ]] then echo " ---> Starting test env" -else python3 manage.py check_db; gunicorn -c config/gunicorn_conf.py newsblur_web.wsgi:application +else python3 manage.py check_db; gunicorn -c config/gunicorn_conf.py --reload newsblur_web.wsgi:application fi