Skip to content

Commit

Permalink
Automagic restart handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
natefoo committed Apr 17, 2022
1 parent 68c3bc7 commit 5e4ee51
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ Options below that control individual file or subdirectory placement can still o
[custom]: vars/layout-custom.yml
[fhs]: http://www.pathname.com/fhs/

**New options for Galaxy 22.01 and later**

The role can now manage the Galaxy service using [gravity][gravity]. This is the default for Galaxy 22.05 and later.
Additionally, support for the `galaxy_restart_handler_name` variable has been removed. If you need to enable your own
custom restart handler, you can use the "`listen`" option to the handler as explained in the
[handler documentation](https://docs.ansible.com/ansible/latest/user_guide/playbooks_handlers.html#using-variables-with-handlers).
The handler should "listen" to the topic `"restart galaxy"`.

[gravity]: https://github.com/galaxyproject/gravity

**New options for Galaxy 18.01 and later**

- `galaxy_config_style` (default: `yaml`): The type of Galaxy configuration file to write, `yaml` for the YAML format supported by uWSGI or `ini-paste` for the traditional PasteDeploy-style INI file
Expand Down Expand Up @@ -223,10 +233,13 @@ Several variables control which functions this role will perform (all default to
- `galaxy_build_client`: Build the Galaxy client application (web UI).
- `galaxy_client_make_target` (default: `client-production-maps`): Set the client build type. Options include: `client`,
`client-production` and `client-production-maps`. See [Galaxy client readme][client-build] for details.
- `galaxy_manage_systemd` (default: `no`): Install a [systemd][systemd] service unit to start and stop Galaxy with the
system (and using the `systemctl` command).
- `galaxy_manage_errordocs` (default: `no`): Install Galaxy-styled 413 and 502 HTTP error documents for nginx. Requires
write privileges for the nginx error document directory.

[client-build]: https://github.com/galaxyproject/galaxy/blob/dev/client/README.md#complete-client-build
[systemd]: https://www.freedesktop.org/wiki/Software/systemd/

**Galaxy code and configuration**

Expand Down Expand Up @@ -323,6 +336,23 @@ The role needs to perform tasks as different users depending on which features y
connecting to the target host. By default, the role will use `become` (i.e. sudo) to perform tasks as the appropriate
user if deemed necessary. Overriding this behavior is discussed in the [defaults file][defaults].

**systemd**

[systemd][systemd] is the standard system init daemon on most modern Linux flavors (and all of the ones supported by
this role). If `galaxy_manage_systemd` is enabled, a `galaxy` service will be configured in systemd to run Galaxy. This
service will be automatically started and configured to start when your system boots. You can control the Galaxy
service with the `systemctl` utility as the `root` user or with `sudo`:

```console
# systemctl start galaxy # start galaxy
# systemctl reload galaxy # attempt a "graceful" reload
# systemctl restart galaxy # perform a hard restart
# systemctl stop galaxy # stop galaxy
```

You can use systemd user mode if you do not have root privileges on your system by setting `galaxy_systemd_root` to
`false`. Add `--user` to the `systemctl` commands above to interact with systemd in user mode:

**Error documents**

- `galaxy_errordocs_dir`: Install Galaxy-styled HTTP 413 and 502 error documents under this directory. The 502 message
Expand All @@ -334,9 +364,6 @@ user if deemed necessary. Overriding this behavior is discussed in the [defaults

**Miscellaneous options**

- `galaxy_restart_handler_name`: The role doesn't restart Galaxy since it doesn't control how Galaxy is started and
stopped. Because of this, you can write your own restart handler and inform the role of your handler's name with this
variable. See the examples
- `galaxy_admin_email_to`: If set, email this address when Galaxy has been updated. Assumes mail is properly configured
on the managed host.
- `galaxy_admin_email_from`: Address to send the aforementioned email from.
Expand Down Expand Up @@ -398,7 +425,6 @@ Install Galaxy as per the current production server best practices:
galaxy_user: galaxy
galaxy_privsep_user: gxpriv
galaxy_group: galaxy
galaxy_restart_handler_name: Restart Galaxy
postgresql_objects_users:
- name: galaxy
password: null
Expand Down Expand Up @@ -453,6 +479,7 @@ Install Galaxy as per the current production server best practices:
supervisorctl:
name: galaxy
state: restarted
listen: restart galaxy
```

License
Expand Down
6 changes: 2 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,17 @@ galaxy_client_build_steps:
- stageLibs
- plugins

# Restart handler is already set if using the systemd options in this role, otherwise you need to define one yourself
galaxy_restart_handler_name: "{{ 'galaxy ' ~ galaxy_systemd_mode ~ ' restart' if galaxy_manage_systemd else 'default restart galaxy handler' }}"

#
# systemd options
#

# Currently `mule` (aka uWSGI) and `gravity` (runs Galaxy 22.01+ under gunicorn) are supported
galaxy_systemd_mode: mule
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 }}"
Expand Down
20 changes: 8 additions & 12 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
---
# defaults file for galaxyproject.galaxy

- name: default restart galaxy handler
debug:
msg: "RESTARTER NOT IMPLEMENTED - Please restart Galaxy manually. You can define your own handler and enable it with `galaxy_restart_handler_name`"

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

- name: galaxy mule start
- name: galaxy systemd start
systemd:
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') }}"

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

- 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"
Expand Down
2 changes: 1 addition & 1 deletion tasks/clone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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
4 changes: 2 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@
tags:
- galaxy_manage_gravity

- name: Include systemd unit setup tasks (Mules)
- name: Include systemd unit setup tasks (Galaxy)
include_tasks:
file: systemd-mule.yml
file: systemd-galaxy.yml
apply:
tags: galaxy_manage_systemd
when: galaxy_manage_systemd and galaxy_systemd_mode in ["mule", "gravity"]
Expand Down
6 changes: 3 additions & 3 deletions tasks/static_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
mode: "{{ galaxy_config_perms }}"
with_items: "{{ galaxy_config_files }}"
notify:
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

- name: Install additional Galaxy config files (template)
template:
Expand All @@ -26,7 +26,7 @@
mode: "{{ galaxy_config_perms }}"
with_items: "{{ galaxy_config_templates }}"
notify:
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

- name: Install local tools
copy:
Expand Down Expand Up @@ -128,7 +128,7 @@
mode: "{{ galaxy_config_perms }}"
notify:
- galaxyctl update
- "{{ galaxy_restart_handler_name }}"
- restart galaxy

remote_user: "{{ galaxy_remote_users.privsep | default(__galaxy_remote_user) }}"
become: "{{ true if galaxy_become_users.privsep is defined else __galaxy_become }}"
Expand Down
11 changes: 8 additions & 3 deletions tasks/systemd-mule.yml → tasks/systemd-galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
- name: Manage Paths
block:

- name: Ensure Galaxy version is set
include_tasks: _inc_galaxy_version.yml
when: __galaxy_major_version is undefined

- name: Deploy Galaxy Unit
template:
owner: "{{ galaxy_systemd_root | ternary('root', omit) }}"
Expand All @@ -11,10 +15,11 @@
src: systemd/galaxy.service.j2
dest: "{{ galaxy_systemd_root | ternary('/etc/systemd/system/', ('~' ~ __galaxy_user_name ~ '/.config/systemd/user') | expanduser) }}/galaxy.service"
notify:
- daemon reload
- "{{ galaxy_restart_handler_name }}"
- systemd daemon reload
- start galaxy
- restart galaxy

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

0 comments on commit 5e4ee51

Please sign in to comment.