view etc/periodic/daily/720.local-triggered-action @ 393:d83f877d7849

Variables that are set but empty need not to set again to a default empty value
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 23 Feb 2023 22:00:40 +0100
parents 8b1740deedbb
children 7c597ee2c8d9
line wrap: on
line source

#!/bin/sh
# -*- indent-tabs-mode: nil; -*-
#
# @(#)@@SIMPLEVERSIONTAG@@
#
# Weekly script to handle actions triggered by newly existing files.
# This is e.g. convenient to notify a running daemon to reload because
# of renewed certificates.
#

# If there is a global system configuration file, suck it in.
if [ -r /etc/defaults/periodic.conf ]
then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

: ${daily_local_triggered_action_enable:=NO}
: ${daily_local_triggered_action_files=}
# e.g. "service nginx onestatus"
: ${daily_local_triggered_action_condition=}
# e.g. "service nginx reload"
: ${daily_local_triggered_action_action=}
: ${daily_local_triggered_action_files_remove:=YES}

case "${daily_local_triggered_action_enable}" in
    [Yy][Ee][Ss])
        echo
        echo "Testing for newly renewed Let's Encrypt certificates"

        rc=0

        _do_action=""
        _remove_files=""

        for _f in ${daily_local_triggered_action_files}; do
            if [ -r "${_f}" ]; then
                _do_action="yes"
                case "${daily_local_triggered_action_files_remove}" in
                    [Yy][Ee][Ss])
                        _remove_files="${_remove_files} ${_f}"
                        ;;
                esac
            fi
        done

        if [ "${_do_action}" = "yes" ]; then
            if [ -z "${daily_local_triggered_action_action}" ]; then
                echo "ERROR: no deploy action defined" 1>&2
                exit 2
            fi

            echo "Deploying newly renewed Let's Encrypt certificates"
            if [ -n "${daily_local_triggered_action_condition}" ]; then
                if ${daily_local_triggered_action_condition} ; then
                    ${daily_local_triggered_action_action}
                    rc=$?
                else
                    rc=1
                fi
            else
                ${daily_local_triggered_action_action}
                rc=$?
            fi

            # Remove trigger files if configured to do so
            if [ ${rc} -eq 0 ]; then
                echo "Removing trigger files..."
                for _rf in ${_remove_files}; do
                    rm -fv "${_rf}"
                done
            fi
        else
            echo "No newly renewed Let's Encrypt certificates found"
        fi
        ;;

    *)
        rc=0
        ;;
esac

exit ${rc}