From 3988f5beb000cb48bc90e775ad5bc6afed60644f Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Mon, 6 Feb 2023 16:41:04 +0100 Subject: [PATCH 1/3] shellcheck fixes --- global/overlay/usr/local/bin/run-cosmos | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/global/overlay/usr/local/bin/run-cosmos b/global/overlay/usr/local/bin/run-cosmos index 5f2cbc1..fdfb85d 100755 --- a/global/overlay/usr/local/bin/run-cosmos +++ b/global/overlay/usr/local/bin/run-cosmos @@ -16,29 +16,29 @@ lock() { eval "exec $fd>$lock_file" # acquier the lock - flock -n $fd \ + flock -n "$fd" \ && return 0 \ || return 1 } eexit() { - local error_str="$@" + local error_str="$*" - echo $error_str + echo "$error_str" exit 1 } main () { - lock $PROGNAME || eexit "Only one instance of $PROGNAME can run at one time." - cosmos $* update - cosmos $* apply + lock "$PROGNAME" || eexit "Only one instance of $PROGNAME can run at one time." + cosmos "$@" update + cosmos "$@" apply touch /var/run/last-cosmos-ok.stamp - find /var/lib/puppet/reports/ -type f -mtime +10 | xargs rm -f + find /var/lib/puppet/reports/ -type f -mtime +10 -print0 | xargs -0 rm -f } -main $* +main "$@" if [ -f /cosmos-reboot ]; then rm -f /cosmos-reboot From 79606f2a6d1919d30902769b58dd61c43b31a023 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Mon, 6 Feb 2023 16:45:53 +0100 Subject: [PATCH 2/3] check for /etc/no-automatic-cosmos in the wrapper, and allow arguments to be passed --- global/overlay/etc/cron.d/cosmos | 2 +- global/overlay/usr/local/libexec/cosmos-cron-wrapper | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/global/overlay/etc/cron.d/cosmos b/global/overlay/etc/cron.d/cosmos index 38d14f5..e7abc17 100644 --- a/global/overlay/etc/cron.d/cosmos +++ b/global/overlay/etc/cron.d/cosmos @@ -1,4 +1,4 @@ SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -*/15 * * * * root test -f /etc/no-automatic-cosmos || /usr/local/libexec/cosmos-cron-wrapper +*/15 * * * * root /usr/local/libexec/cosmos-cron-wrapper diff --git a/global/overlay/usr/local/libexec/cosmos-cron-wrapper b/global/overlay/usr/local/libexec/cosmos-cron-wrapper index 2df85b5..ae66810 100755 --- a/global/overlay/usr/local/libexec/cosmos-cron-wrapper +++ b/global/overlay/usr/local/libexec/cosmos-cron-wrapper @@ -1,10 +1,12 @@ #!/usr/bin/env bash -RUN_COSMOS=/usr/local/bin/run-cosmos +test -f /etc/no-automatic-cosmos && exit 0 + +RUN_COSMOS='/usr/local/bin/run-cosmos' SCRIPTHERDER_CMD='' -if [ -f /usr/local/bin/scriptherder ]; then +if [ -x /usr/local/bin/scriptherder ]; then SCRIPTHERDER_CMD='/usr/local/bin/scriptherder --mode wrap --syslog --name cosmos --' fi -${SCRIPTHERDER_CMD} ${RUN_COSMOS} +exec ${SCRIPTHERDER_CMD} ${RUN_COSMOS} "$@" From 12b2412ea78cc5b8302a0be5608d8f10a972f917 Mon Sep 17 00:00:00 2001 From: Fredrik Thulin Date: Mon, 6 Feb 2023 17:12:01 +0100 Subject: [PATCH 3/3] run cron at boot too, to e.g. get new firewall rules installed --- global/overlay/etc/cron.d/cosmos | 2 ++ 1 file changed, 2 insertions(+) diff --git a/global/overlay/etc/cron.d/cosmos b/global/overlay/etc/cron.d/cosmos index e7abc17..3840f8c 100644 --- a/global/overlay/etc/cron.d/cosmos +++ b/global/overlay/etc/cron.d/cosmos @@ -2,3 +2,5 @@ SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin */15 * * * * root /usr/local/libexec/cosmos-cron-wrapper + +@reboot root sleep 30; /usr/local/libexec/cosmos-cron-wrapper