Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions roles/debian/ssl/templates/le_cron.sh.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/bash

# Function to send email notification
send_email_notification() {
local recipient="$1"
local subject="$2"
local body="$3"

echo -e "$body" | mail -s "$subject" "$recipient"
}

# stop services
{% for service in _ssl_services %}
/usr/sbin/service {{ service }} stop
Expand All @@ -20,8 +29,11 @@ for site in ${SITES[@]}; do
SITESSTRING+=" -d $site"
done

# run certbot
{{ ssl.certbot_renew_command }} --{{ _ssl_web_server }} --http-01-port {{ ssl.http_01_port }} --expand$SITESSTRING
# run certbot and capture the output
certbot_output=$( {{ ssl.certbot_renew_command }} --{{ _ssl_web_server }} --http-01-port {{ ssl.http_01_port }} --expand$SITESSTRING 2>&1 )

# Capture exit code of Certbot command
certbot_exit_code=$?

# start services again
{% for service in _ssl_services %}
Expand All @@ -31,4 +43,14 @@ done
# reload dependent services
{% for service in ssl.reload %}
/usr/sbin/service {{ service }} {{ ssl.reload_command }}
{% endfor %}
{% endfor %}

if [ $certbot_exit_code -ne 0 ]; then
# Certbot failed, send email notification
recipient="{{ ssl.email }}"
subject="Certbot Renewal Failed"
body="Certbot renewal failed with the following output:

$certbot_output"
send_email_notification "$recipient" "$subject" "$body"
fi