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_requires: []
|
||||||
container_wants: []
|
container_wants: []
|
||||||
container_add_capabilities: []
|
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]
|
systemd_restart_units: "{{ systemd_restart_units + [container_name ~ '.service'] }}" # noqa: var-naming[no-role-prefix]
|
||||||
changed_when: true
|
changed_when: true
|
||||||
notify: Apply systemd unit restarts
|
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
|
type: bool
|
||||||
required: false
|
required: false
|
||||||
default: true
|
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 {}
|
else {}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
_container_reload_commands:
|
||||||
|
kill: podman kill --signal HUP {{ container_name }}
|
||||||
|
command: podman exec {{ container_name }} {{ container_reload_command }}
|
||||||
|
|
||||||
_container_quadlet_unit_options: |
|
_container_quadlet_unit_options: |
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Container {{ container_name }}
|
Description=Container {{ container_name }}
|
||||||
@@ -90,8 +94,12 @@ _container_quadlet_auto_start_options: |
|
|||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
_container_quadlet_reload_options: |
|
||||||
|
[Service]
|
||||||
|
ExecReload={{ _container_reload_commands[container_reload_method] }}
|
||||||
_container_quadlet_options_incl_empty:
|
_container_quadlet_options_incl_empty:
|
||||||
- "{{ 'AutoUpdate=registry' if container_auto_update else '' }}"
|
- "{{ 'AutoUpdate=registry' if container_auto_update else '' }}"
|
||||||
- "{{ _container_quadlet_unit_options }}"
|
- "{{ _container_quadlet_unit_options }}"
|
||||||
- "{{ _container_quadlet_auto_start_options if container_auto_start else '' }}"
|
- "{{ _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('!=', '') }}"
|
_container_quadlet_options: "{{ _container_quadlet_options_incl_empty | select('!=', '') }}"
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ service_container_devices: []
|
|||||||
service_container_secrets: []
|
service_container_secrets: []
|
||||||
service_container_env: {}
|
service_container_env: {}
|
||||||
service_container_add_capabilities: []
|
service_container_add_capabilities: []
|
||||||
|
service_container_reload_method: none
|
||||||
|
service_container_reload_command: ""
|
||||||
|
|
||||||
service_database_type: none
|
service_database_type: none
|
||||||
service_database_additional_networks: []
|
service_database_additional_networks: []
|
||||||
|
|||||||
@@ -298,6 +298,26 @@ argument_specs:
|
|||||||
default: []
|
default: []
|
||||||
elements: str
|
elements: str
|
||||||
|
|
||||||
|
service_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
|
||||||
|
service_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
|
||||||
|
default: ""
|
||||||
|
|
||||||
service_database_type:
|
service_database_type:
|
||||||
description:
|
description:
|
||||||
- Database type to set up.
|
- Database type to set up.
|
||||||
@@ -553,6 +573,25 @@ argument_specs:
|
|||||||
type: list
|
type: list
|
||||||
required: false
|
required: false
|
||||||
elements: str
|
elements: str
|
||||||
|
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
|
||||||
|
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
|
||||||
|
default: ""
|
||||||
secrets:
|
secrets:
|
||||||
description:
|
description:
|
||||||
- >
|
- >
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
container_secrets: "{{ _service_additional_container_secrets }}"
|
container_secrets: "{{ _service_additional_container_secrets }}"
|
||||||
container_env: "{{ _service_additional_container.env }}"
|
container_env: "{{ _service_additional_container.env }}"
|
||||||
container_add_capabilities: "{{ _service_additional_container.add_capabilities }}"
|
container_add_capabilities: "{{ _service_additional_container.add_capabilities }}"
|
||||||
|
container_reload_method: "{{ _service_additional_container.reload_method }}"
|
||||||
|
container_reload_command: "{{ _service_additional_container.reload_command }}"
|
||||||
container_requires: "{{ _service_additional_container_requires }}"
|
container_requires: "{{ _service_additional_container_requires }}"
|
||||||
container_wants: "{{ _service_additional_container_wants }}"
|
container_wants: "{{ _service_additional_container_wants }}"
|
||||||
container_auto_update: "{{ service_auto_update }}"
|
container_auto_update: "{{ service_auto_update }}"
|
||||||
|
|||||||
@@ -24,7 +24,9 @@
|
|||||||
dest: "{{ item[1] }}"
|
dest: "{{ item[1] }}"
|
||||||
mode: "{{ item[0].mode | default('0644') }}"
|
mode: "{{ item[0].mode | default('0644') }}"
|
||||||
validate: "{{ validate if item[0].template_validate_command is defined else omit }}"
|
validate: "{{ validate if item[0].template_validate_command is defined else omit }}"
|
||||||
notify: Restart container service {{ service_name }}
|
notify: >-
|
||||||
|
{{ 'Reload' if service_container_reload_method != 'none' else 'Restart' }}
|
||||||
|
container service {{ service_name }}
|
||||||
loop: "{{ _service_all_template_mounts | zip(_service_all_template_mount_host_files) }}"
|
loop: "{{ _service_all_template_mounts | zip(_service_all_template_mount_host_files) }}"
|
||||||
vars:
|
vars:
|
||||||
validate: >-
|
validate: >-
|
||||||
|
|||||||
@@ -48,6 +48,8 @@
|
|||||||
container_secrets: "{{ _service_container_secrets }}"
|
container_secrets: "{{ _service_container_secrets }}"
|
||||||
container_env: "{{ service_container_env }}"
|
container_env: "{{ service_container_env }}"
|
||||||
container_add_capabilities: "{{ service_container_add_capabilities }}"
|
container_add_capabilities: "{{ service_container_add_capabilities }}"
|
||||||
|
container_reload_method: "{{ service_container_reload_method }}"
|
||||||
|
container_reload_command: "{{ service_container_reload_command }}"
|
||||||
container_requires: "{{ _service_container_requires }}"
|
container_requires: "{{ _service_container_requires }}"
|
||||||
container_wants: "{{ _service_container_wants }}"
|
container_wants: "{{ _service_container_wants }}"
|
||||||
container_auto_update: "{{ service_auto_update }}"
|
container_auto_update: "{{ service_auto_update }}"
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ _service_additional_container_same_image_defaults:
|
|||||||
devices: "{{ service_container_devices }}"
|
devices: "{{ service_container_devices }}"
|
||||||
env: "{{ service_container_env }}"
|
env: "{{ service_container_env }}"
|
||||||
add_capabilities: "{{ service_container_add_capabilities }}"
|
add_capabilities: "{{ service_container_add_capabilities }}"
|
||||||
|
reload_method: "{{ service_container_reload_method }}"
|
||||||
|
reload_command: "{{ service_container_reload_command }}"
|
||||||
|
|
||||||
_service_additional_container_different_image_defaults:
|
_service_additional_container_different_image_defaults:
|
||||||
user: ""
|
user: ""
|
||||||
@@ -28,6 +30,8 @@ _service_additional_container_different_image_defaults:
|
|||||||
publish_ports: []
|
publish_ports: []
|
||||||
env: {}
|
env: {}
|
||||||
add_capabilities: []
|
add_capabilities: []
|
||||||
|
reload_method: none
|
||||||
|
reload_command: ""
|
||||||
secrets: []
|
secrets: []
|
||||||
|
|
||||||
_service_additional_same_image_containers: >-
|
_service_additional_same_image_containers: >-
|
||||||
|
|||||||
Reference in New Issue
Block a user