Skip to content

Commit

Permalink
Port galaxyproject/ansible-galaxy#152 from standalone role
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed May 31, 2022
1 parent e714d34 commit 0f98686
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 26 deletions.
2 changes: 1 addition & 1 deletion roles/clone/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
diff: "{{ galaxy_diff_mode_verbose }}"
register: __galaxy_git_update_result
notify:
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

- name: Report Galaxy version change
debug:
Expand Down
7 changes: 4 additions & 3 deletions roles/config/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
group: "{{ galaxy_group_name | default(omit) }}"
with_items: "{{ galaxy_config_files }}"
notify:
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

- name: Install additional Galaxy config files (template)
template:
Expand All @@ -20,7 +20,7 @@
group: "{{ galaxy_group_name | default(omit) }}"
with_items: "{{ galaxy_config_templates }}"
notify:
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

- name: Install local tools
copy:
Expand Down Expand Up @@ -124,4 +124,5 @@
mode: "{{ galaxy_config_perms }}"
group: "{{ galaxy_group_name | default(omit) }}"
notify:
- "{{ galaxy_restart_handler_name }}"
- galaxyctl update
- restart galaxy
2 changes: 2 additions & 0 deletions roles/config/templates/galaxy.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
{%- set galaxy_config = {} %}
{% endif %}

{% set _gravity_config = galaxy_config.gravity | default(galaxy_gravity_config_default) -%}
{{ {'gravity': _gravity_config} | to_nice_yaml(indent=4) }}

{% set _uwsgi_config = galaxy_config.uwsgi | default(galaxy_uwsgi_config_default) -%}
{% if galaxy_uwsgi_yaml_parser == 'libyaml' %}
Expand Down
31 changes: 27 additions & 4 deletions roles/defaults/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ galaxy_local_tools_dir: "{{ galaxy_shared_ro_root }}/local_tools"
galaxy_mutable_data_dir: "{{ galaxy_local_rw_root }}/lib"
galaxy_mutable_config_dir: "{{ galaxy_local_rw_root }}/lib/config"
galaxy_cache_dir: "{{ galaxy_local_rw_root }}/tmp/cache"
galaxy_log_dir: "{{ galaxy_local_rw_root }}/log"

galaxy_shed_tools_dir: "{{ galaxy_shared_rw_root }}/lib/shed_tools"
galaxy_tool_dependency_dir: "{{ galaxy_shared_rw_root }}/lib/dependencies"
Expand All @@ -66,6 +67,7 @@ galaxy_local_rw_dirs:
- "{{ galaxy_mutable_data_dir }}"
- "{{ galaxy_mutable_config_dir }}"
- "{{ galaxy_cache_dir }}"
- "{{ galaxy_log_dir }}"

galaxy_shared_rw_dirs:
- "{{ galaxy_shed_tools_dir }}"
Expand Down Expand Up @@ -213,6 +215,16 @@ galaxy_errordocs_prefix: /error
galaxy_config_files: []
galaxy_config_templates: []

# Default Gravity configuration
galaxy_gravity_state_dir: "{{ (galaxy_local_rw_root, 'gravity') | path_join }}"
galaxy_gravity_config_default:
galaxy_root: "{{ galaxy_server_dir }}"
log_dir: "{{ galaxy_log_dir }}"
virtualenv: "{{ galaxy_venv_dir }}"
app_server: gunicorn
gunicorn:
bind: localhost:8080

# Default uWSGI configuration
galaxy_uwsgi_yaml_parser: internal
galaxy_uwsgi_config_default:
Expand Down Expand Up @@ -260,16 +272,27 @@ galaxy_client_build_steps:


# Restart handler is already set if using the systemd options in this role, otherwise you need to define one yourself
galaxy_manage_gravity: "{{ false if __galaxy_major_version is version('22.05', '<') else true }}"
galaxy_manage_systemd: false
# FIXME: document, implement for Gravity
galaxy_restart_handler_name: "{{ 'systemd galaxy restart' if (galaxy_systemd_mode == 'mule' and galaxy_manage_systemd) else 'default restart galaxy handler' }}"

#
# systemd options
#

# Currently `mule` is the only systemd mode
galaxy_systemd_mode: mule
# Currently `mule` (aka uWSGI) and `gravity` (runs Galaxy 22.01+ under gunicorn) are supported
galaxy_systemd_mode: "{{ 'mule' if __galaxy_major_version is version('22.05', '<') else 'gravity' }}"

# Control whether the systemd service unit is installed/controlled as root or the Galaxy user
galaxy_systemd_root: true

# The command that systemd will run to start Galaxy, depends on galaxy_systemd_mode or override
galaxy_systemd_command: "{{ __galaxy_systemd_command[galaxy_systemd_mode] }}"
__galaxy_systemd_command:
mule: "{{ galaxy_venv_dir }}/bin/uwsgi {{ '--yaml' if galaxy_config_style in ('yaml', 'yml') else '--ini' }} {{ galaxy_config_file }}"
gravity: "{{ galaxy_venv_dir }}/bin/galaxyctl start --foreground --quiet"

# TimeoutStartSec is unfortunately also the timeout used for reload operations, which take longer
galaxy_systemd_timeout_start_sec: "{{ (galaxy_systemd_mode == 'gravity') | ternary(60, 10) }}"

# Systemd will create cgroups to enforce these limits (sizes in GB), override individual limits by setting
# `galaxy_systemd_memory_limit.<limit>` in your vars.
Expand Down
5 changes: 0 additions & 5 deletions roles/defaults/handlers/main.yml

This file was deleted.

9 changes: 9 additions & 0 deletions roles/dependencies/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@
PYTHONPATH: null
VIRTUAL_ENV: "{{ galaxy_venv_dir }}"
when: galaxy_additional_venv_packages

- name: Configure $GRAVITY_STATE_DIR in virtualenv activate
blockinfile:
path: "{{ galaxy_venv_dir }}/bin/activate"
marker: "# {mark} GALAXYPROJECT.GALAXY ROLE ANSIBLE MANAGED BLOCK"
block: |
# Galaxy Gravity per-instance state directory configured by galaxyproject.galaxy Ansible role
GRAVITY_STATE_DIR={{ galaxy_gravity_state_dir | quote }}
export GRAVITY_STATE_DIR
14 changes: 14 additions & 0 deletions roles/gravity/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

- name: galaxy gravity restart
command: "{{ galaxy_venv_dir }}/bin/galaxyctl graceful"
environment:
GRAVITY_STATE_DIR: "{{ galaxy_gravity_state_dir }}"
when: "galaxy_systemd_mode == 'gravity'"
listen: "restart galaxy"

- name: galaxyctl update
command: "{{ galaxy_venv_dir }}/bin/galaxyctl update"
environment:
GRAVITY_STATE_DIR: "{{ galaxy_gravity_state_dir }}"
when: "galaxy_systemd_mode == 'gravity'"
4 changes: 4 additions & 0 deletions roles/gravity/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

dependencies:
- role: galaxyproject.galaxy.defaults
17 changes: 17 additions & 0 deletions roles/gravity/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

- name: Gravity setup
block:

- name: Register Galaxy config with Gravity
command: "{{ galaxy_venv_dir }}/bin/galaxyctl register {{ galaxy_config_file }}"
args:
creates: "{{ galaxy_gravity_state_dir }}/configstate.yaml"

- name: Update Gravity process management files
command: "{{ galaxy_venv_dir }}/bin/galaxyctl update"
args:
creates: "{{ galaxy_gravity_state_dir }}/supervisor/supervisord.conf.d"

environment:
GRAVITY_STATE_DIR: "{{ galaxy_gravity_state_dir }}"
19 changes: 15 additions & 4 deletions roles/systemd/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
---
# defaults file for galaxyproject.galaxy

- name: systemd daemon reload
systemd:
daemon_reload: yes
scope: "{{ galaxy_systemd_root | ternary(omit, 'user') }}"

- name: systemd galaxy restart
- name: galaxy systemd start
systemd:
name: galaxy.service
state: restarted
name: galaxy.service
state: started
scope: "{{ galaxy_systemd_root | ternary(omit, 'user') }}"
when: "galaxy_systemd_mode == 'gravity'"
listen: "start galaxy"

- name: galaxy mule restart
systemd:
name: galaxy.service
state: restarted
scope: "{{ galaxy_systemd_root | ternary(omit, 'user') }}"
when: "galaxy_systemd_mode == 'mule'"
listen: "restart galaxy"
1 change: 1 addition & 0 deletions roles/systemd/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

dependencies:
- role: galaxyproject.galaxy.defaults
- role: galaxyproject.galaxy.version
16 changes: 9 additions & 7 deletions roles/systemd/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
---

- name: Deploy Galaxy systemd service unit
- name: Deploy Galaxy Unit
template:
owner: root
group: root
owner: "{{ galaxy_systemd_root | ternary('root', omit) }}"
group: "{{ galaxy_systemd_root | ternary('root', omit) }}"
mode: 0644
src: galaxy.service.j2
dest: /etc/systemd/system/galaxy.service
src: systemd/galaxy.service.j2
dest: "{{ galaxy_systemd_root | ternary('/etc/systemd/system/', ('~' ~ galaxy_user_name ~ '/.config/systemd/user') | expanduser) }}/galaxy.service"
notify:
- systemd daemon reload
- systemd galaxy restart
- start galaxy
- restart galaxy

- name: Enable Galaxy systemd service Unit
- name: Enable Galaxy service unit
systemd:
name: galaxy.service
enabled: yes
scope: "{{ galaxy_systemd_root | ternary(omit, 'user') }}"
11 changes: 9 additions & 2 deletions roles/systemd/templates/galaxy.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,24 @@ After=time-sync.target
[Service]
UMask=022
Type=simple
{% if galaxy_systemd_root %}
User={{ galaxy_user_name }}
Group={{ galaxy_group_name }}
{% endif %}
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 }}
TimeoutStartSec={{ galaxy_systemd_timeout_start_sec }}
ExecStart={{ galaxy_systemd_command }}
{% if galaxy_systemd_mode == 'gravity' %}
ExecReload={{ galaxy_venv_dir }}/bin/galaxyctl graceful
ExecStop={{ galaxy_venv_dir }}/bin/galaxyctl shutdown
{% endif %}

Environment=HOME={{ galaxy_local_rw_root }}
Environment=VIRTUAL_ENV={{ galaxy_venv_dir }}
Environment=PATH={{ galaxy_venv_dir }}/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
Environment=DOCUTILSCONFIG=
Environment=PYTHONPATH={{ galaxy_dynamic_job_rules_dir }}
Environment=GRAVITY_STATE_DIR={{ galaxy_gravity_state_dir }}
{% for env in galaxy_systemd_env %}
Environment={{ env }}
{% endfor %}
Expand Down

0 comments on commit 0f98686

Please sign in to comment.