From 453eb323fb919945256d20c9e1eb6aef2e4cc4ab Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Mon, 18 Apr 2022 21:17:43 +0300 Subject: [PATCH] simplified cron runner. --- docker/files/cron.sh | 28 ++++++++++++++++++---------- docker/files/entrypoint.sh | 6 +++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/docker/files/cron.sh b/docker/files/cron.sh index 85035ec9..64fd377a 100755 --- a/docker/files/cron.sh +++ b/docker/files/cron.sh @@ -1,25 +1,33 @@ #!/usr/bin/env sh +UID=$(id -u) NOW=$(date +"%Y_%m_%d") WS_UID=${WS_UID:-1000} WS_GID=${WS_GID:-1000} +WS_CRON_DEBUG=${WS_CRON_DEBUG:-'v'} # check for data path. if [ -z "${WS_DATA_PATH}" ]; then WS_DATA_PATH="/config" fi -if [ "1" == "${WS_CRON_IMPORT}" ] || [ "1" == "${WS_CRON_EXPORT}" ] || [ "1" == "${WS_CRON_PUSH}" ]; then - LOGFILE="${WS_DATA_PATH}/logs/cron/${NOW}.log" +LOGFILE="${WS_DATA_PATH}/logs/cron/${NOW}.log" - if [ ! -d "${WS_DATA_PATH}/logs/cron/" ]; then +# Check cron logs path. +if [ ! -d "${WS_DATA_PATH}/logs/cron/" ]; then + if [ 0 == "${UID}" ]; then runuser -u www-data -- mkdir -p "${WS_DATA_PATH}/logs/cron/" + else + mkdir -p "${WS_DATA_PATH}/logs/cron/" fi - - if [ ! -f "${LOGFILE}" ]; then - runuser -u www-data -- touch "${LOGFILE}" - chown ${WS_UID}:${WS_GID} "${LOGFILE}" - fi - - /usr/bin/console scheduler:run -o >>"${LOGFILE}" +fi + +if [ 0 == "${UID}" ]; then + OUTPUT=$(runuser -u www-data -- /usr/bin/console scheduler:run -o -${WS_CRON_DEBUG}) +else + OUTPUT=$(/usr/bin/console scheduler:run -o -${WS_CRON_DEBUG}) +fi + +if [ ! -z "${OUTPUT}" ]; then + echo ${OUTPUT} >${LOGFILE} fi diff --git a/docker/files/entrypoint.sh b/docker/files/entrypoint.sh index dee2e25a..ed5431a3 100755 --- a/docker/files/entrypoint.sh +++ b/docker/files/entrypoint.sh @@ -36,7 +36,7 @@ if [ ! -f "/usr/bin/run-app-cron" ]; then chmod +x /usr/bin/run-app-cron fi -if [ 0 == "${WS_NO_CHOWN}" ]; then +if [ -z "${WS_NO_CHOWN}" ]; then chown -R www-data:www-data /config /var/lib/nginx/ fi @@ -45,12 +45,12 @@ fi /usr/bin/console storage:migrations /usr/bin/console storage:maintenance -if [ 0 == "${WS_DISABLE_HTTP}" ]; then +if [ -z "${WS_DISABLE_HTTP}" ]; then echo "Starting Nginx server.." nginx fi -if [ "1" == "${WS_CRON_IMPORT}" ] || [ "1" == "${WS_CRON_EXPORT}" ] || [ "1" == "${WS_CRON_PUSH}" ]; then +if [ -z "${WS_DISABLE_CRON}" ]; then echo "Starting cron..." /usr/sbin/crond -b -l 2 fi