container, service: Support reloading containers on template file change

This commit is contained in:
uumas
2026-06-08 19:11:16 +03:00
parent 3e84073f39
commit e28a4097a0
10 changed files with 85 additions and 1 deletions

View File

@@ -14,3 +14,4 @@ container_auto_update: true
container_requires: []
container_wants: []
container_add_capabilities: []
container_reload_method: none

View File

@@ -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"

View File

@@ -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

View File

@@ -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('!=', '') }}"