From 8e0128a00dd0d94d167b93a6113f33a570b4ff28 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 25 Feb 2023 19:34:23 +0100 Subject: docker: rename schedule.sh to run_cron.sh --- docker/Dockerfile | 2 +- docker/entrypoint.sh | 2 +- docker/run_cron.sh | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ docker/schedule.sh | 62 ---------------------------------------------------- 4 files changed, 64 insertions(+), 64 deletions(-) create mode 100755 docker/run_cron.sh delete mode 100755 docker/schedule.sh diff --git a/docker/Dockerfile b/docker/Dockerfile index 0f2afdb..7e15042 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -22,7 +22,7 @@ ENV SSH_AUTH_SOCK "$ssh_sock_path" COPY ["docker/entrypoint.sh", "/"] COPY ["docker/get_output_dir.py", "/"] -COPY ["docker/schedule.sh", "/"] +COPY ["docker/run_cron.sh", "/"] COPY ["cgitize/", "/usr/src/cgitize/"] ENV SCHEDULE_ON_START=1 diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 59d4814..fc3417b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -29,7 +29,7 @@ secure_repo_dir() { main() { secure_repo_dir - exec "$script_dir/schedule.sh" "$@" + exec "$script_dir/run_cron.sh" "$@" } main "$@" diff --git a/docker/run_cron.sh b/docker/run_cron.sh new file mode 100755 index 0000000..db7ae26 --- /dev/null +++ b/docker/run_cron.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021 Egor Tensin +# This file is part of the "cgitize" project. +# For details, see https://github.com/egor-tensin/cgitize. +# Distributed under the MIT License. + +set -o errexit -o nounset -o pipefail +shopt -s inherit_errexit lastpipe + +schedule_to_cron() { + local schedule + for schedule; do + case "$schedule" in + 15min) echo '*/15 * * * *' ;; + hourly) echo '0 * * * *' ;; + daily) echo '0 0 * * *' ;; + weekly) echo '0 0 * * 1' ;; + monthly) echo '0 0 1 * *' ;; + *) + echo "$schedule" + ;; + esac + done +} + +make_task_script() { + echo "#!/bin/bash +cd -- "$( pwd )" && $( printf -- ' %q' "$@" )" +} + +setup_cron_task() { + local schedule + schedule="${SCHEDULE:-once}" + + if [ "$schedule" = once ]; then + exec "$@" + fi + + schedule="$( schedule_to_cron "$schedule" )" + + make_task_script "$@" > /task.sh + chmod +x /task.sh + + if [ -n "$SCHEDULE_ON_START" ]; then + # Run the task once when the container is started. + /task.sh + fi + + local crontab + crontab="$schedule /task.sh +# This is the new crontab." + + echo "$crontab" | crontab - + exec crond -f +} + +main() { + setup_cron_task "$@" +} + +main "$@" diff --git a/docker/schedule.sh b/docker/schedule.sh deleted file mode 100755 index db7ae26..0000000 --- a/docker/schedule.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (c) 2021 Egor Tensin -# This file is part of the "cgitize" project. -# For details, see https://github.com/egor-tensin/cgitize. -# Distributed under the MIT License. - -set -o errexit -o nounset -o pipefail -shopt -s inherit_errexit lastpipe - -schedule_to_cron() { - local schedule - for schedule; do - case "$schedule" in - 15min) echo '*/15 * * * *' ;; - hourly) echo '0 * * * *' ;; - daily) echo '0 0 * * *' ;; - weekly) echo '0 0 * * 1' ;; - monthly) echo '0 0 1 * *' ;; - *) - echo "$schedule" - ;; - esac - done -} - -make_task_script() { - echo "#!/bin/bash -cd -- "$( pwd )" && $( printf -- ' %q' "$@" )" -} - -setup_cron_task() { - local schedule - schedule="${SCHEDULE:-once}" - - if [ "$schedule" = once ]; then - exec "$@" - fi - - schedule="$( schedule_to_cron "$schedule" )" - - make_task_script "$@" > /task.sh - chmod +x /task.sh - - if [ -n "$SCHEDULE_ON_START" ]; then - # Run the task once when the container is started. - /task.sh - fi - - local crontab - crontab="$schedule /task.sh -# This is the new crontab." - - echo "$crontab" | crontab - - exec crond -f -} - -main() { - setup_cron_task "$@" -} - -main "$@" -- cgit v1.2.3