container, service: Support reloading containers on template file change
This commit is contained in:
@@ -14,3 +14,4 @@ container_auto_update: true
|
||||
container_requires: []
|
||||
container_wants: []
|
||||
container_add_capabilities: []
|
||||
container_reload_method: none
|
||||
|
||||
@@ -4,3 +4,9 @@
|
||||
systemd_restart_units: "{{ systemd_restart_units + [container_name ~ '.service'] }}" # noqa: var-naming[no-role-prefix]
|
||||
changed_when: true
|
||||
notify: Apply systemd unit restarts
|
||||
|
||||
- name: Reload container service {{ container_name }}
|
||||
ansible.builtin.systemd_service:
|
||||
name: "{{ container_name }}.service"
|
||||
state: reloaded
|
||||
when: "container_name ~ '.service' not in systemd_restart_units"
|
||||
|
||||
@@ -212,3 +212,21 @@ argument_specs:
|
||||
type: bool
|
||||
required: false
|
||||
default: true
|
||||
container_reload_method:
|
||||
description: |
|
||||
How to reload configuration when systemctl reload is called
|
||||
kill: Sends SIGHUP to the container
|
||||
command: Runs the specified command inside the container
|
||||
type: str
|
||||
required: false
|
||||
default: none
|
||||
choices:
|
||||
- kill
|
||||
- command
|
||||
- none
|
||||
container_reload_command:
|
||||
description: >-
|
||||
Command to run inside container when systemctl reload is called.
|
||||
Required if container_reload_method is command, ignored otherwise.
|
||||
type: str
|
||||
required: false
|
||||
|
||||
@@ -69,6 +69,10 @@ _container_labels: >-
|
||||
else {}
|
||||
}}
|
||||
|
||||
_container_reload_commands:
|
||||
kill: podman kill --signal HUP {{ container_name }}
|
||||
command: podman exec {{ container_name }} {{ container_reload_command }}
|
||||
|
||||
_container_quadlet_unit_options: |
|
||||
[Unit]
|
||||
Description=Container {{ container_name }}
|
||||
@@ -90,8 +94,12 @@ _container_quadlet_auto_start_options: |
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
_container_quadlet_reload_options: |
|
||||
[Service]
|
||||
ExecReload={{ _container_reload_commands[container_reload_method] }}
|
||||
_container_quadlet_options_incl_empty:
|
||||
- "{{ 'AutoUpdate=registry' if container_auto_update else '' }}"
|
||||
- "{{ _container_quadlet_unit_options }}"
|
||||
- "{{ _container_quadlet_auto_start_options if container_auto_start else '' }}"
|
||||
- "{{ _container_quadlet_reload_options if container_reload_method != 'none' else '' }}"
|
||||
_container_quadlet_options: "{{ _container_quadlet_options_incl_empty | select('!=', '') }}"
|
||||
|
||||
Reference in New Issue
Block a user