Skip to content

Commit

Permalink
support reports, mules
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Jun 2, 2021
1 parent 528caf4 commit 74f824f
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 0 deletions.
16 changes: 16 additions & 0 deletions defaults/main.yml
Expand Up @@ -19,6 +19,9 @@ galaxy_fetch_dependencies: yes
galaxy_build_client: yes
galaxy_manage_errordocs: no
galaxy_backup_configfiles: yes
galaxy_manage_systemd: no # For Galaxy
galaxy_manage_systemd_reports: no # For Reports


# Control whether to output verbose task diffs (e.g. when performing a git update) when running Ansible with --diff.
# Only suppresses diff on tasks that are likely to be verbose, not all tasks
Expand Down Expand Up @@ -274,3 +277,16 @@ galaxy_client_build_steps:
- stageLibs
- plugins


# systemd options
galaxy_systemd:
env: "" #Any extra env vars
mode: mule
memory_limit:
mule: 16
reports: 5
#workflow: 5
#zergpool: 8
#zergling: 16
#handler: 5
stats: 4001 # Port for stats to listen on.
27 changes: 27 additions & 0 deletions tasks/main.yml
Expand Up @@ -120,3 +120,30 @@
when: galaxy_manage_errordocs
tags:
- galaxy_manage_errordocs

#- name: Include systemd unit setup tasks (Zerg Mode)
#include_tasks:
#file: systemd-zerg.yml
#apply:
#tags: galaxy_manage_systemd
#when: galaxy_systemd.mode == "zerg"
#tags:
#- galaxy_manage_systemd

- name: Include systemd unit setup tasks (Mules)
include_tasks:
file: systemd-mule.yml
apply:
tags: galaxy_manage_systemd
when: galaxy_systemd.mode == "mule"
tags:
- galaxy_manage_systemd

- name: Include systemd unit setup tasks (Reports)
include_tasks:
file: systemd-reports.yml
apply:
tags: galaxy_manage_systemd_reports
when: galaxy_manage_systemd_reports
tags:
- galaxy_manage_systemd_reports
24 changes: 24 additions & 0 deletions tasks/systemd-mule.yml
@@ -0,0 +1,24 @@
---

- name: Manage Paths
block:

- name: Deploy Galaxy Unit
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy.service.j2
dest: /etc/systemd/system/galaxy.service
notify:
- daemon reload
- galaxy mule start

- name: Enable Galaxy Unit
systemd:
name: galaxy.service
enabled: yes

remote_user: "{{ galaxy_remote_users.root | default(__galaxy_remote_user) }}"
become: "{{ true if galaxy_become_users.root is defined else __galaxy_become }}"
become_user: "{{ galaxy_become_users.root | default(__galaxy_become_user) }}"
23 changes: 23 additions & 0 deletions tasks/systemd-reports.yml
@@ -0,0 +1,23 @@
---

- name: Manage Paths
block:

- name: Deploy Galaxy Reports unit
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy-reports.service.j2
dest: /etc/systemd/system/galaxy-reports.service
notify: daemon reload

- name: Enable reports and ensure it is running
systemd:
name: galaxy-reports.service
enabled: yes
state: started

remote_user: "{{ galaxy_remote_users.root | default(__galaxy_remote_user) }}"
become: "{{ true if galaxy_become_users.root is defined else __galaxy_become }}"
become_user: "{{ galaxy_become_users.root | default(__galaxy_become_user) }}"
78 changes: 78 additions & 0 deletions tasks/systemd-zerg.yml
@@ -0,0 +1,78 @@
---

- name: Manage Paths
block:

- name: Deploy Zergpool unit
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy-zergpool.service.j2
dest: /etc/systemd/system/galaxy-zergpool.service
notify: daemon reload

- name: Deploy Zergling units
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy-zergling@.service.j2
dest: /etc/systemd/system/galaxy-zergling@.service
notify: daemon reload

- name: Deploy handler units
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy-handler@.service.j2
dest: /etc/systemd/system/galaxy-handler@.service
notify: daemon reload

- name: Deploy workflow units
template:
owner: root
group: root
mode: 0644
src: systemd/galaxy-workflow-scheduler@.service.j2
dest: /etc/systemd/system/galaxy-workflow-scheduler@.service
when: galaxy_systemd.processes.workflow > 0
notify: daemon reload

# TODO: In case of changes? Not sure this is necessary.
#- name: just force systemd to reread configs (2.4 and above)
#systemd:
#daemon_reload: yes

- name: Enable zergpool and ensure it is running
systemd:
name: galaxy-zergpool.service
enabled: yes
state: started

- name: Enable relevant zerglings
systemd:
name: "galaxy-zergling@{{ item }}.service"
enabled: yes
state: started
loop: "{{ range(0, galaxy_systemd.processes.zerglings) | list }}"

- name: Enable relevant handlers
systemd:
name: "galaxy-handler@{{ item }}.service"
enabled: yes
state: started
loop: "{{ range(0, galaxy_systemd.processes.handlers) | list }}"

- name: Enable relevant workflows
systemd:
name: "galaxy-workflow-scheduler@{{ item }}.service"
enabled: yes
state: started
loop: "{{ range(0, galaxy_systemd.processes.workflow) | list }}"
when: galaxy_systemd_workflow_schedulers > 0

remote_user: "{{ galaxy_remote_users.root | default(__galaxy_remote_user) }}"
become: "{{ true if galaxy_become_users.root is defined else __galaxy_become }}"
become_user: "{{ galaxy_become_users.root | default(__galaxy_become_user) }}"
23 changes: 23 additions & 0 deletions templates/systemd/galaxy-handler@.service.j2
@@ -0,0 +1,23 @@
[Unit]
Description=Galaxy Handlers
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=30
ExecStart={{ galaxy_venv_dir }}/bin/python ./scripts/galaxy-main -c {{ galaxy_config_dir }}/{{ galaxy_config_file_basename }} --server-name=handler_{{ galaxy_instance_codename }}_%I
Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin DOCUTILSCONFIG='' PYTHONPATH={{ galaxy_dynamic_job_rules_dir }} {{ galaxy_systemd.env }}
MemoryLimit={{ galaxy_systemd.memory_limit.handler }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions templates/systemd/galaxy-reports.service.j2
@@ -0,0 +1,23 @@
[Unit]
Description=Galaxy Reports
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=10
ExecStart={{ galaxy_venv_dir }}/bin/uwsgi {{ '--yaml' if galaxy_config_style in ('yaml', 'yml') else '--ini' }} {{ galaxy_reports_path }} --stats 127.0.0.1:4030
Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin DOCUTILSCONFIG= PYTHONPATH={{ galaxy_dynamic_job_rules_dir }} {{ galaxy_systemd.env }}
MemoryLimit={{ galaxy_systemd.memory_limit.reports }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions templates/systemd/galaxy-workflow-scheduler@.service.j2
@@ -0,0 +1,23 @@
[Unit]
Description=Galaxy Workflow Scheduler
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=30
ExecStart={{ galaxy_venv_dir }}/bin/python ./scripts/galaxy-main -c {{ galaxy_config_dir }}/{{ galaxy_config_file_basename }} --server-name=workflow_scheduler_{{ galaxy_instance_codename }}_%I
Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin DOCUTILSCONFIG='' PYTHONPATH={{ galaxy_dynamic_job_rules_dir }} {{ galaxy_systemd.env }}
MemoryLimit={{ galaxy_systemd.memory_limit.workflow }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
24 changes: 24 additions & 0 deletions templates/systemd/galaxy-zergling@.service.j2
@@ -0,0 +1,24 @@
[Unit]
Description=Galaxy Zerglings
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=10
ExecStart={{ galaxy_venv_dir }}/bin/uwsgi {{ '--yaml' if galaxy_systemd_zergling_uwsgi_config_style in ('yaml', 'yml') else '--ini' }} {{ galaxy_systemd_zergling_uwsgi_config_file }} --stats 127.0.0.1:401%I {% if galaxy_zergpool %}--zerg {{ galaxy_zergpool_listen_path }}{% else %}--socket 127.0.0.1:400%I{% endif %}

Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin DOCUTILSCONFIG='' PYTHONPATH={{ galaxy_dynamic_job_rules_dir }} {{ galaxy_systemd.env }}
MemoryLimit={{ galaxy_systemd.memory_limit.zergling }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions templates/systemd/galaxy-zergpool.service.j2
@@ -0,0 +1,23 @@
[Unit]
Description=Galaxy Zergpool
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=10
ExecStart={{ galaxy_venv_dir }}/bin/uwsgi --master --zerg-pool {{ galaxy_zergpool_listen_path }}:{{ galaxy_zergpool_listen_addr }}
Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
MemoryLimit={{ galaxy_systemd.memory_limit.zergpool }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions templates/systemd/galaxy.service.j2
@@ -0,0 +1,23 @@
[Unit]
Description=Galaxy
After=network.target
After=time-sync.target

[Service]
UMask=022
Type=simple
User={{ galaxy_user.name }}
Group={{ __galaxy_user_group }}
WorkingDirectory={{ galaxy_server_dir }}
TimeoutStartSec=10
ExecStart={{ galaxy_venv_dir }}/bin/uwsgi {{ '--yaml' if galaxy_config_style in ('yaml', 'yml') else '--ini' }} {{ galaxy_config_file }} {% if galaxy_systemd.stats %}--stats 127.0.0.1:{{ galaxy_systemd.stats }}{% endif %}
Environment=HOME={{ galaxy_root }} VIRTUAL_ENV={{ galaxy_venv_dir }} PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin DOCUTILSCONFIG= PYTHONPATH={{ galaxy_dynamic_job_rules_dir }} {{ galaxy_systemd.env }}
MemoryLimit={{ galaxy_systemd.memory_limit.mule }}G
Restart=always

MemoryAccounting=yes
CPUAccounting=yes
BlockIOAccounting=yes

[Install]
WantedBy=multi-user.target
31 changes: 31 additions & 0 deletions templates/systemd/resource_controls.conf.j2
@@ -0,0 +1,31 @@
;;
;; This file is managed by Ansible. ALL CHANGES WILL BE OVERWRITTEN.
;;
{% if item.real_memory_limit is defined %}
{% set memlim = item.real_memory_limit %}
{% elif item.real_memory_limit_percent is defined and item.real_memory_limit_percent > 1.0 %}
{% set memlim = ((item.real_memory_limit_percent / 100.0) * ansible_memory_mb.real.total) | int ~ "M" %}
{% elif item.real_memory_limit_percent is defined %}
{% set memlim = (item.real_memory_limit_percent * ansible_memory_mb.real.total) | int ~ "M" %}
{% else %}
{% set memlim = none %}
{% endif -%}

{%- set memlim_mb = memlim | default(ansible_memory_mb.real.total * 1024 * 1024) | human_to_bytes / 1024 // 1024 %}
{% if item.swap_limit is defined %}
{% set memswlim = (memlim_mb + (item.swap_limit | human_to_bytes / 1024 // 1024)) ~ "M" %}
{% elif item.swap_limit_percent is defined and item.swap_limit_percent > 1.0 %}
{% set memswlim = (memlim_mb + (item.swap_limit_percent / 100.0) * ansible_memory_mb.swap.total) | int ~ "M" %}
{% elif item.swap_limit_percent is defined %}
{% set memswlim = (memlim_mb + item.swap_limit_percent * ansible_memory_mb.swap.total) | int ~ "M" %}
{% else %}
{% set memswlim = none %}
{% endif -%}

[{{ item.unit_type | default("service") | title }}]
{% if memlim is not none %}
MemoryLimit={{ memlim }}
{% endif %}
{% if memswlim is not none %}
ExecStartPost=/bin/bash -c "echo {{ memswlim }} > /sys/fs/cgroup/memory/system.slice/{{ item.name }}.{{ item.unit_type | default('service') | lower }}/memory.memsw.limit_in_bytes"
{% endif %}

0 comments on commit 74f824f

Please sign in to comment.