diff --git a/type/__single_binary_service/man.rst b/type/__single_binary_service/man.rst index 65b4fc0..464785f 100644 --- a/type/__single_binary_service/man.rst +++ b/type/__single_binary_service/man.rst @@ -90,6 +90,11 @@ binary If `--unpack` is used, a binary with this name must be unpacked. Otherwise, the contents of `--url` will be placed under this binary name. +env + An `env` file consiting of `ENVIRONMENT_VARIABLE=VALUE`, one variable per + line. + Empty lines and those starting with `#` are ignored. + service-args Any extra arguments to pass along with `--service-exec`. Beware that any service-args having the format `--config=/etc/foo.cfg` should be diff --git a/type/__single_binary_service/manifest b/type/__single_binary_service/manifest index 8288b94..e9d1691 100755 --- a/type/__single_binary_service/manifest +++ b/type/__single_binary_service/manifest @@ -112,7 +112,7 @@ if [ "${USER}" != "root" ] && \ --system \ --state "${STATE}" \ --home "${USER_HOME_DIR}" \ - --comment "cdist-managed ${SERVICE_NAME} user" \ + --comment "cdist-managed service user" \ ${USER_CREATE_HOME} # Track dependencies service_require="${service_require} __user/${USER}" @@ -136,11 +136,21 @@ fi +# These messages will trigger a service restart (overridden for systemd) +service_config_reload_pattern="^__file${CONFIG_FILE_DEST}" + # This should setup the object in $service_definition_require # See above. case "${INIT}" in systemd) if [ -z "${SERVICE_DEFINITION}" ]; then + SYSTEMD_ENV_FILE="/etc/systemd/system/${SERVICE_NAME}.env" + __file "${SYSTEMD_ENV_FILE}" \ + --mode 0400 \ + --source "${__object}/parameter/env" + # We need to take into account the envionment file for systemd too + service_config_reload_pattern="(${service_config_reload_pattern}|^__file${SYSTEMD_ENV_FILE})" + SERVICE_DEFINITION="$(cat <&1 exec chpst -u "${USER}:${GROUP}" ${SERVICE_EXEC} EOF )" @@ -279,10 +296,10 @@ EOF --onchange "${perform_service_upgrade}" \ --source "-" else - # We only restart here if there was a config change + # We only restart here if there was a config or env change # but there was not a version change require="${service_require}" __check_messages \ "single_binary_service_${__object_id}" \ - --pattern "^__file${CONFIG_FILE_DEST}" \ + --pattern "${service_config_reload_pattern}" \ --execute "$(sv_cmd restart)" fi diff --git a/type/__single_binary_service/parameter/default/env b/type/__single_binary_service/parameter/default/env new file mode 100644 index 0000000..e69de29 diff --git a/type/__single_binary_service/parameter/optional b/type/__single_binary_service/parameter/optional index 7c88cb4..e51681b 100644 --- a/type/__single_binary_service/parameter/optional +++ b/type/__single_binary_service/parameter/optional @@ -1,4 +1,5 @@ config-file-source +env user group state