Allow to define pre-start and post-stop tasks

WHile you can leverage config_overrides for that, it might become
tricky if you need to define more then 1 pre/post exec tasks.

Change-Id: I3d8b36f5e9f4be89eaff848d8ba88a38ce5285e4
This commit is contained in:
Dmitriy Rabotyagov 2022-10-14 12:11:06 +02:00
parent 4bc059e9d9
commit 62bd24859e
3 changed files with 18 additions and 0 deletions

View File

@ -102,8 +102,10 @@ systemd_environment: {}
# can contain the following options:
# `service_name` -- (required) used to define the name of the service. This is typically the name of the executable.
# `service_type` -- (optional) Set the service type, default is "simple".
# `execstartpres` -- (optional) Set the program that wil lexecute before service startup.
# `execstarts` -- (required) Set the program to start, when the service is simple the list has a max length of 1.
# `execstops` -- (optional) Set the program to stop, when the service is simple the list has a max length of 1.
# `execstopposts` -- (optional) Set the program that wil lexecute after service stop.
# `after_targets` -- (optional) Start the service after this list of dependency units.
# `partof` -- (optional) Set the systemd "partof" directive. This ties a service unit to another.
# `config_overrides` -- (optional) This allows any section or key=value pair to be set within the systemd unit file.
@ -198,6 +200,8 @@ systemd_environment: {}
# execstops
# - /usr/bin/stopcmd1
# - /usr/bin/stopcmd2
# execstopposts:
# - /usr/local/bin/hook
# sockets:
# - socket_name: SocketServiceZ
# after_targets:

View File

@ -0,0 +1,6 @@
---
features:
- |
Now you can define ``execstartpres`` and ``execstopposts`` keys for the
`systemd_services` structure. They will allow to define pre-start and
post-stop service executables and must be defined as lists.

View File

@ -32,6 +32,10 @@ Environment="{{ key }}={{ value }}"
EnvironmentFile={{ item.environment_file | default(systemd_environment_file) }}
{% endif %}
{% for execstartpre in item.execstartpres | default([]) %}
ExecStartPre={{ execstartpre }}
{% endfor %}
{% set _execstarts = item.execstarts %}
{% if _execstarts is string %}
{% set _execstarts = [_execstarts] %}
@ -56,6 +60,10 @@ ExecReload={{ execreload }}
ExecStop={{ execstop }}
{% endfor %}
{% for execstoppost in item.execstopposts | default([]) %}
ExecStopPost={{ execstoppost }}
{% endfor %}
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec={{ systemd_TimeoutSec }}
{% if service_type != 'oneshot' %}