#!/bin/bash _logfile="/var/log/renew_ssl.txt" echo "Date: $(date +%Y%m%d)" | tee -a $_logfile echo "Nb of args: $?" | tee -a $_logfile if [ ! -z "$RENEWED_DOMAINS" ]; then for domain in $RENEWED_DOMAINS; do if [[ $domain = www.* ]]; then domain=`echo $domain | sed 's/www.\(.*\)/\1/g'` else echo "Processing domain: $domain" | tee -a $_logfile mkdir -p /etc/haproxy/ssl/archives if test -f /etc/haproxy/ssl/certs/$domain.pem; then cp /etc/haproxy/ssl/certs/$domain.pem /etc/haproxy/ssl/archives/$domain.pem.$(date +%Y%m%d) fi cat /etc/letsencrypt/live/$domain/privkey.pem /etc/letsencrypt/live/$domain/fullchain.pem > /etc/haproxy/ssl/certs/$domain.pem # check if pem file in haproxy dir is empty and rm it if it is if [ ! -s /etc/haproxy/ssl/certs/$domain.pem ]; then rm /etc/haproxy/ssl/certs/$domain.pem fi /usr/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg && /bin/systemctl reload haproxy.service echo "$domain renewed at $(date)" | tee -a $_logfile fi done else echo "$domain renewal failed at $(date)" | tee -a $_logfile exit 0 fi #/* vim: set tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab */