Allow PartOf to be defined in unit section

This patch allows PartOf to be defined in the [Unit] section of
a given systemd service. Doing so creates a one-way dependency
on the given service that is limited to stopping and restarting of units.

Change-Id: I2b802d868ba0c8b085379daae8a9fa4f36281eea
This commit is contained in:
James Denton 2019-01-25 16:17:53 +00:00 committed by Kevin Carter
parent 9c86c4832e
commit 6907b0c9f2
2 changed files with 10 additions and 0 deletions

View File

@ -88,6 +88,11 @@ systemd_default_service_type: simple
# VAR3: "$word 5 6"
systemd_environment: {}
# Set the systemd "partof" directive. This ties a service unit to another.
# Documentation for PartOf can be found here
# https://www.freedesktop.org/software/systemd/man/systemd.unit.html#PartOf=
# systemd_partof: unit-name.service
# The systemd services dictionary is a set of services that will be created. The dictionary
# can contain the following options:
# `service_name` -- (required) used to define the name of the service. This is typically the name of the executable.
@ -95,6 +100,7 @@ systemd_environment: {}
# `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.
# `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.
# `program_sandboxing` -- (optional) Case sensitive Key=Value pairs for service Sandboxing
# `program_accounting` -- (optional) Case sensitive Key=Value pairs for service Accounting

View File

@ -10,6 +10,10 @@ After={{ target }}
Documentation={{ item }}
{% endfor %}
{% if (systemd_partof is defined) or (item.partof is defined) %}
PartOf={{ item.partof | default(systemd_partof) }}
{% endif %}
[Service]
{% set service_type = item.service_type | default(systemd_default_service_type) %}
Type={{ service_type }}