diff --git a/Dockerfiles/base/data/docker-entrypoint.d/100-base-libs.sh b/Dockerfiles/base/data/docker-entrypoint.d/100-base-libs.sh index 361ae343..3283de70 100755 --- a/Dockerfiles/base/data/docker-entrypoint.d/100-base-libs.sh +++ b/Dockerfiles/base/data/docker-entrypoint.d/100-base-libs.sh @@ -13,6 +13,8 @@ set -o pipefail ### Log to stdout/stderr ### log() { + set -o noglob # prevent message from being expanded + local type="${1}" # ok, warn or err local message="${2}" # msg to print local debug="${3}" # 0: only warn and error, >0: ok and info @@ -38,7 +40,10 @@ log() { else printf "${clr_err}[???] %s${clr_rst}\n" "${message}" 1>&2 # stdout -> stderr fi + + set +o noglob } +export -f log ### @@ -57,7 +62,7 @@ run() { fi /bin/sh -c "LANG=C LC_ALL=C ${cmd}" } - +export -f run ### ### Is argument a positive integer? @@ -73,7 +78,7 @@ isint() { env_set() { printenv "${1}" >/dev/null 2>&1 } - +export -f env_set ### ### Get env variable by name @@ -91,6 +96,7 @@ env_get() { # Just output the env value printenv "${1}" } +export -f env_get ############################################################ diff --git a/Dockerfiles/base/data/docker-entrypoint.d/102-cron.sh b/Dockerfiles/base/data/docker-entrypoint.d/102-cron.sh new file mode 100755 index 00000000..0eee774f --- /dev/null +++ b/Dockerfiles/base/data/docker-entrypoint.d/102-cron.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -e +set -u +set -o pipefail + + +########################################################### +# Functions +############################################################ + +# add line to devilbox's crontab, if not already there +# and start cron service +cron_add() { + # save the entire line in one variable + line="$*" + + DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )" + + # check if line already exists in crontab + crontab -l -u devilbox | grep "$line" > /dev/null + status=$? + + if [ $status -ne 0 ] + then + log "info" "cron: adding line '${line}' ..." "$DEBUG_LEVEL" + (crontab -l -u devilbox; echo "$line";) | crontab -u devilbox - + fi + + # make sure the cron service is running + if ! service cron status >/dev/null + then + service cron start + fi +} +export -f cron_add + +cron_remove() { + # save the entire line in one variable + line=$* + + DEBUG_LEVEL="$( env_get "DEBUG_ENTRYPOINT" "0" )" + + # check if line already exists in crontab + crontab -l -u devilbox | grep "$line" > /dev/null + status=$? + + if [ $status -eq 0 ]; then + log "info" "cron: removing line '${line}' ..." "$DEBUG_LEVEL" + (crontab -l -u devilbox | grep -v "$line";) | crontab -u devilbox - + fi +} +export -f cron_remove diff --git a/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh b/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh index ba53df1d..a833a270 100755 --- a/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh +++ b/Dockerfiles/prod/data/docker-entrypoint.d/310-custom-startup-scripts.sh @@ -10,7 +10,7 @@ set -o pipefail ############################################################ ### -### Execute custom uesr-supplied scripts +### Execute custom user-supplied scripts ### execute_custom_scripts() { local script_dir="${1}" @@ -27,7 +27,7 @@ execute_custom_scripts() { for script_f in ${script_files}; do script_name="$( basename "${script_f}" )" log "info" "Executing custom startup script: ${script_name}" "${debug}" - if ! bash "${script_f}"; then + if ! bash "${script_f}" "${debug}"; then log "err" "Failed to execute script" "${debug}" exit 1 fi @@ -43,6 +43,10 @@ if ! command -v find >/dev/null 2>&1; then echo "find not found, but required." exit 1 fi +if ! command -v sort >/dev/null 2>&1; then + echo "sort not found, but required." + exit 1 +fi if ! command -v basename >/dev/null 2>&1; then echo "basename not found, but required." exit 1