Skip to content

Commit

Permalink
Merge pull request #6113 from dimagi/dmr/fix-supervisor-file-management
Browse files Browse the repository at this point in the history
Fix supervisor service file management
  • Loading branch information
dannyroberts authored Sep 5, 2023
2 parents 66d3232 + 907a668 commit c2df8e4
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 113 deletions.
12 changes: 2 additions & 10 deletions src/commcare_cloud/ansible/deploy_commcarehq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@
- webworkers
tasks:
- set_fact:
supervisor_files:
- "{{ celery_managed_files|default([]) }}"
- "{{ pillowtop_managed_files|default([]) }}"
- "{{ proxy_managed_files|default([]) }}"
- "{{ webworker_managed_files|default([]) }}"
- "{{ formplayer_managed_files|default([]) }}"
- "{{ mgmt_cmd_managed_files|default([]) }}"
- "{{ prometheus_managed_files|default([]) }}"
- "{{ prometheus_django_runner_managed_files|default([]) }}"
supervisor_files: "{{ supervisor_service_files.values()|selectattr('should_exist')|map(attribute='file_path') }}"
- name: "Find supervisor config files"
become: true
shell: find {{ service_home|quote }} -type f
Expand All @@ -125,7 +117,7 @@
path: "{{ item }}"
state: absent
with_items: "{{ contents.stdout_lines }}"
when: item not in supervisor_files|sum(start=[])
when: item not in supervisor_files
tags: services

- name: Celery tasks cleanup Cron job
Expand Down
60 changes: 60 additions & 0 deletions src/commcare_cloud/ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,63 @@ ansible_become_password: "{{ ansible_sudo_pass }}"

# Java version for Formplayer
java_17_bin_path: /usr/lib/jvm/java-1.17.0-openjdk-amd64/bin

# To find this complete list, you can run:
# $ find . -type f | grep templates/supervisor_
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_django.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_celery_beat.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_prometheus.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_pillowtop.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_celery_workers.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_websockets.conf
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_formplayer_spring.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_management_commands.conf.j2
# ./src/commcare_cloud/ansible/roles/commcarehq/templates/supervisor_celery_flower.conf.j2
#
# The only ones not matching this pattern are celery_bash_runner and django_bash_runner
supervisor_service_files:
django:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_django.conf"
template: ../templates/supervisor_django.conf.j2
should_exist: "{{ inventory_hostname in groups['webworkers'] }}"
celery_beat:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_beat.conf"
template: ../templates/supervisor_celery_beat.conf.j2
should_exist: "{{ app_processes_config.celery_processes.get(inventory_hostname).beat is defined }}"
celery_flower:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_flower.conf"
template: ../templates/supervisor_celery_flower.conf.j2
should_exist: "{{ app_processes_config.celery_processes.get(inventory_hostname).flower is defined }}"
celery_workers:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_workers.conf"
template: ../templates/supervisor_celery_workers.conf.j2
should_exist: "{{ app_processes_config.celery_processes.get(inventory_hostname) is defined }}"
celery_bash_runner:
file_path: "{{ service_home }}/{{ deploy_env }}_celery_bash_runner.sh"
template: ../templates/celery_bash_runner.sh.j2
should_exist: "{{ app_processes_config.celery_processes.get(inventory_hostname) is defined }}"
formplayer_spring:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_formplayer_spring.conf"
template: ../templates/supervisor_formplayer_spring.conf.j2
should_exist: "{{ inventory_hostname in groups['formplayer'] }}"
management_commands:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_management_commands.conf"
template: ../templates/supervisor_management_commands.conf.j2
should_exist: "{{ app_processes_config.management_commands.get(inventory_hostname, {}) }}"
pillowtop:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_pillowtop.conf"
template: ../templates/supervisor_pillowtop.conf.j2
should_exist: "{{ inventory_hostname in groups['pillowtop'] }}"
websockets:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_websockets.conf"
template: ../templates/supervisor_websockets.conf
should_exist: "{{ inventory_hostname in groups['proxy'] and run_websockets_wsgi }}"
prometheus:
file_path: "{{ service_home }}/{{ deploy_env }}_supervisor_prometheus.conf"
template: ../templates/supervisor_prometheus.conf.j2
should_exist: "{{ prometheus_monitoring_enabled|default(False) }}"
# only used with prometheus
django_bash_runner:
file_path: "{{ service_home }}/{{ deploy_env }}_django_bash_runner.sh"
template: ../templates/django_bash_runner.sh.j2
should_exist: "{{ prometheus_monitoring_enabled|default(False) }}"
37 changes: 10 additions & 27 deletions src/commcare_cloud/ansible/roles/commcarehq/tasks/celery.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,35 @@
# Note: Make sure to add queues with associated tasks to the solo_queues list in
# validate_app_processes_config(), in app_processes.py, so they don't share a process with another queue.
- set_fact:
celery_bash_runner: "{{ service_home }}/{{ deploy_env }}_celery_bash_runner.sh"
supervisor_celery_flower: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_flower.conf"
supervisor_celery_beat: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_beat.conf"
supervisor_celery_workers: "{{ service_home }}/{{ deploy_env }}_supervisor_celery_workers.conf"

- set_fact:
celery_managed_files:
- "{{celery_bash_runner}}"
- "{{supervisor_celery_flower}}"
- "{{supervisor_celery_beat}}"
- "{{supervisor_celery_workers}}"

- name: Add celery_bash_runner files
template:
src: "../templates/celery_bash_runner.sh.j2"
dest: "{{ item.file_name }}"
src: "{{ supervisor_service_files.celery_bash_runner.template }}"
dest: "{{ supervisor_service_files.celery_bash_runner.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
with_items:
- file_name: "{{ celery_bash_runner }}"
when: supervisor_service_files.celery_bash_runner.should_exist

- name: define special celery services
template:
src: "{{ item.template }}"
dest: "{{ item.file_name }}"
dest: "{{ item.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0600
when: item.should_apply
when: item.should_exist
with_items:
- template: ../templates/supervisor_celery_flower.conf.j2
file_name: "{{supervisor_celery_flower}}"
should_apply: "{{ app_processes_config.celery_processes.get(inventory_hostname).flower is defined }}"
- template: ../templates/supervisor_celery_beat.conf.j2
file_name: "{{supervisor_celery_beat}}"
should_apply: "{{ app_processes_config.celery_processes.get(inventory_hostname).beat is defined }}"
- "{{ supervisor_service_files.celery_flower }}"
- "{{ supervisor_service_files.celery_beat }}"

- name: define celery workers
template:
src: "../templates/supervisor_celery_workers.conf.j2"
dest: "{{ supervisor_celery_workers }}"
src: "{{ supervisor_service_files.celery_workers.template }}"
dest: "{{ supervisor_service_files.celery_workers.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: app_processes_config.celery_processes.get(inventory_hostname) is defined
when: supervisor_service_files.celery_workers.should_exist
with_items:
- env_vars:
http_proxy: "{% if http_proxy_address is defined %}http://{{ http_proxy_address }}:{{ http_proxy_port }}{% endif %}"
Expand Down
16 changes: 3 additions & 13 deletions src/commcare_cloud/ansible/roles/commcarehq/tasks/formplayer.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
- set_fact:
supervisor_formplayer_spring: "{{ service_home }}/{{ deploy_env }}_supervisor_formplayer_spring.conf"
tags:
- formplayer_deploy

- set_fact:
formplayer_managed_files:
- "{{ supervisor_formplayer_spring }}"
tags:
- formplayer_deploy

- name: create services home
become: yes
file:
Expand All @@ -23,11 +12,12 @@
- name: define formplayer spring services
become: yes
template:
src: "../templates/supervisor_formplayer_spring.conf.j2"
dest: "{{ supervisor_formplayer_spring }}"
src: "{{ supervisor_service_files.formplayer_spring.template }}"
dest: "{{ supervisor_service_files.formplayer_spring.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: supervisor_service_files.formplayer_spring.should_exist
with_items:
- env_vars:
http_proxy: "{% if http_proxy_address is defined %}http://{{ http_proxy_address }}:{{ http_proxy_port }}{% endif %}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
- set_fact:
supervisor_management_commands: "{{ service_home }}/{{ deploy_env }}_supervisor_management_commands.conf"

- set_fact:
mgmt_cmd_managed_files:
- "{{ supervisor_management_commands }}"

- name: define management command services
become: yes
template:
src: "../templates/supervisor_management_commands.conf.j2"
dest: "{{ supervisor_management_commands }}"
src: "{{ supervisor_service_files.management_commands.template }}"
dest: "{{ supervisor_service_files.management_commands.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: app_processes_config.management_commands.get(inventory_hostname, {})
when: supervisor_service_files.management_commands.should_exist
with_items:
- env_vars:
TMPDIR: '{{ encrypted_tmp }}'
Expand Down
12 changes: 3 additions & 9 deletions src/commcare_cloud/ansible/roles/commcarehq/tasks/pillowtop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
- set_fact:
supervisor_pillowtop: "{{ service_home }}/{{ deploy_env }}_supervisor_pillowtop.conf"

- set_fact:
pillowtop_managed_files:
- "{{ supervisor_pillowtop }}"

- name: define pillowtop services
become: yes
template:
src: "../templates/supervisor_pillowtop.conf.j2"
dest: "{{ supervisor_pillowtop }}"
src: "{{ supervisor_service_files.pillowtop.template }}"
dest: "{{ supervisor_service_files.pillowtop.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: supervisor_service_files.pillowtop.should_exist
with_items:
- env_vars:
TMPDIR: '{{ encrypted_tmp }}'
Expand Down
13 changes: 3 additions & 10 deletions src/commcare_cloud/ansible/roles/commcarehq/tasks/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
- set_fact:
supervisor_prometheus: "{{ service_home }}/{{ deploy_env }}_supervisor_prometheus.conf"

- set_fact:
prometheus_managed_files:
- "{{ supervisor_prometheus }}"

- name: Creates Prometheus Metrics directory
become: yes
file:
Expand All @@ -17,9 +10,9 @@
- name: define prometheus service
become: yes
template:
src: "../templates/supervisor_prometheus.conf.j2"
dest: "{{ supervisor_prometheus }}"
src: "{{ supervisor_service_files.prometheus.template }}"
dest: "{{ supervisor_service_files.prometheus.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: prometheus_monitoring_enabled|default(False)
when: supervisor_service_files.prometheus.should_exist
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
- set_fact:
prometheus_django_runner_managed_files:
- "{{ django_bash_runner_path }}"

- name: Add django_bash_runner
become: yes
template:
src: "../templates/django_bash_runner.sh.j2"
dest: "{{ django_bash_runner_path }}"
src: "{{ supervisor_service_files.django_bash_runner.template }}"
dest: "{{ supervisor_service_files.django_bash_runner.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: prometheus_monitoring_enabled|default(False)
when: supervisor_service_files.django_bash_runner.should_exist
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
- set_fact:
supervisor_websockets: "{{ service_home }}/{{ deploy_env }}_supervisor_websockets.conf"

- set_fact:
proxy_managed_files:
- "{{ supervisor_websockets }}"

- name: define websockets services
become: yes
template:
src: "../templates/supervisor_websockets.conf"
dest: "{{ supervisor_websockets }}"
src: "{{ supervisor_service_files.websockets.template }}"
dest: "{{ supervisor_service_files.websockets.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: supervisor_service_files.websockets.should_exist
12 changes: 3 additions & 9 deletions src/commcare_cloud/ansible/roles/commcarehq/tasks/webworkers.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
- set_fact:
supervisor_django: "{{ service_home }}/{{ deploy_env }}_supervisor_django.conf"

- set_fact:
webworker_managed_files:
- "{{ supervisor_django }}"

- name: define django worker service
become: yes
template:
src: "../templates/supervisor_django.conf.j2"
dest: "{{ supervisor_django }}"
src: "{{ supervisor_service_files.django.template }}"
dest: "{{ supervisor_service_files.django.file_path }}"
owner: "{{ cchq_user }}"
group: "{{ cchq_user }}"
mode: 0644
when: supervisor_service_files.django.should_exist
with_items:
- env_vars:
http_proxy: "{% if http_proxy_address is defined %}http://{{ http_proxy_address }}:{{ http_proxy_port }}{% endif %}"
Expand Down
3 changes: 1 addition & 2 deletions src/commcare_cloud/ansible/roles/commcarehq/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ code_source: "{{ code_releases }}/{{ ansible_date_time.date }}_{{ ansible_date_t
python_name: python{{ python_version }}
virtualenv_source: "{{ code_source }}/python_env-{{ python_version }}"

django_bash_runner_path: "{{ service_home }}/{{ deploy_env }}_django_bash_runner.sh"
django_bash_runner: "/bin/bash {{ django_bash_runner_path }}"
django_bash_runner: "/bin/bash {{ supervisor_service_files.django_bash_runner.file_path }}"
django_direct_runner: "{{ virtualenv_home }}/bin/python {{ code_home }}/manage.py"

formplayer_java: "{{ formplayer_java_version | default('java') }}"

This file was deleted.

0 comments on commit c2df8e4

Please sign in to comment.