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

View File

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