Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison etc/periodic/daily/720.local-triggered-action @ 391:8b1740deedbb
Refactor: Renamed the weekly 800.local-certbot-post-deploy to a daily 720.local-triggered-action.
This is because the script is generic enough to not only work for
certbot (ACME, Let's Encrypt) related deploy actions.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Thu, 23 Feb 2023 21:56:54 +0100 |
| parents | etc/periodic/weekly/800.local-certbot-post-deploy@9921352225a9 |
| children | d83f877d7849 |
comparison
equal
deleted
inserted
replaced
| 390:015a9d7e3d55 | 391:8b1740deedbb |
|---|---|
| 1 #!/bin/sh | |
| 2 # -*- indent-tabs-mode: nil; -*- | |
| 3 # | |
| 4 # @(#)@@SIMPLEVERSIONTAG@@ | |
| 5 # | |
| 6 # Weekly script to handle actions triggered by newly existing files. | |
| 7 # This is e.g. convenient to notify a running daemon to reload because | |
| 8 # of renewed certificates. | |
| 9 # | |
| 10 | |
| 11 # If there is a global system configuration file, suck it in. | |
| 12 if [ -r /etc/defaults/periodic.conf ] | |
| 13 then | |
| 14 . /etc/defaults/periodic.conf | |
| 15 source_periodic_confs | |
| 16 fi | |
| 17 | |
| 18 : ${daily_local_triggered_action_enable:=NO} | |
| 19 : ${daily_local_triggered_action_files:=} | |
| 20 # e.g. "service nginx onestatus" | |
| 21 : ${daily_local_triggered_action_condition:=} | |
| 22 # e.g. "service nginx reload" | |
| 23 : ${daily_local_triggered_action_action:=} | |
| 24 : ${daily_local_triggered_action_files_remove:=YES} | |
| 25 | |
| 26 case "${daily_local_triggered_action_enable}" in | |
| 27 [Yy][Ee][Ss]) | |
| 28 echo | |
| 29 echo "Testing for newly renewed Let's Encrypt certificates" | |
| 30 | |
| 31 rc=0 | |
| 32 | |
| 33 _do_action="" | |
| 34 _remove_files="" | |
| 35 | |
| 36 for _f in ${daily_local_triggered_action_files}; do | |
| 37 if [ -r "${_f}" ]; then | |
| 38 _do_action="yes" | |
| 39 case "${daily_local_triggered_action_files_remove}" in | |
| 40 [Yy][Ee][Ss]) | |
| 41 _remove_files="${_remove_files} ${_f}" | |
| 42 ;; | |
| 43 esac | |
| 44 fi | |
| 45 done | |
| 46 | |
| 47 if [ "${_do_action}" = "yes" ]; then | |
| 48 if [ -z "${daily_local_triggered_action_action}" ]; then | |
| 49 echo "ERROR: no deploy action defined" 1>&2 | |
| 50 exit 2 | |
| 51 fi | |
| 52 | |
| 53 echo "Deploying newly renewed Let's Encrypt certificates" | |
| 54 if [ -n "${daily_local_triggered_action_condition}" ]; then | |
| 55 if ${daily_local_triggered_action_condition} ; then | |
| 56 ${daily_local_triggered_action_action} | |
| 57 rc=$? | |
| 58 else | |
| 59 rc=1 | |
| 60 fi | |
| 61 else | |
| 62 ${daily_local_triggered_action_action} | |
| 63 rc=$? | |
| 64 fi | |
| 65 | |
| 66 # Remove trigger files if configured to do so | |
| 67 if [ ${rc} -eq 0 ]; then | |
| 68 echo "Removing trigger files..." | |
| 69 for _rf in ${_remove_files}; do | |
| 70 rm -fv "${_rf}" | |
| 71 done | |
| 72 fi | |
| 73 else | |
| 74 echo "No newly renewed Let's Encrypt certificates found" | |
| 75 fi | |
| 76 ;; | |
| 77 | |
| 78 *) | |
| 79 rc=0 | |
| 80 ;; | |
| 81 esac | |
| 82 | |
| 83 exit ${rc} |
