[__single_binary_service] Support customisation of systemd units

Requested by pedro
This commit is contained in:
evilham 2021-08-04 21:00:52 +02:00
parent c5929f397d
commit afa48b1028
2 changed files with 11 additions and 4 deletions

View file

@ -60,6 +60,8 @@ if [ -z "${SERVICE_DESCRIPTION}" ]; then
SERVICE_DESCRIPTION="cdist-managed '${SERVICE_NAME}' service" SERVICE_DESCRIPTION="cdist-managed '${SERVICE_NAME}' service"
fi fi
SERVICE_DEFINITION="$(cat "${__object}/parameter/service-definition" 2>/dev/null || true)"
DOWNLOAD_URL="$(cat "${__object}/parameter/url")" DOWNLOAD_URL="$(cat "${__object}/parameter/url")"
CHECKSUM="$(cat "${__object}/parameter/checksum")" CHECKSUM="$(cat "${__object}/parameter/checksum")"
SHOULD_VERSION="$(cat "${__object}/parameter/version")" SHOULD_VERSION="$(cat "${__object}/parameter/version")"
@ -102,10 +104,8 @@ INIT="$(cat "${__global}/explorer/init")"
# TODO: Support non-systemd # TODO: Support non-systemd
case "${INIT}" in case "${INIT}" in
systemd) systemd)
__systemd_unit "${SERVICE_NAME}.service" \ if [ -z "${SERVICE_DEFINITION}" ]; then
--source "-" \ SERVICE_DEFINITION="$(cat <<EOF
--state "${STATE}" \
--enablement-state "enabled" <<EOF
[Unit] [Unit]
Description=${SERVICE_DESCRIPTION} Description=${SERVICE_DESCRIPTION}
After=network.target After=network.target
@ -121,6 +121,12 @@ Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
)"
fi
echo ${SERVICE_DEFINITION} | __systemd_unit "${SERVICE_NAME}.service" \
--source "-" \
--state "${STATE}" \
--enablement-state "enabled"
service_require="${service_require} __systemd_unit/${SERVICE_NAME}.service" service_require="${service_require} __systemd_unit/${SERVICE_NAME}.service"
;; ;;

View file

@ -6,4 +6,5 @@ binary
service-args service-args
service-exec service-exec
service-description service-description
service-definition
unpack-args unpack-args