ansible-role-postgresql-pgpool/templates/pgpool-letsencrypt-acme.sh.j2

47 lines
1.4 KiB
Django/Jinja

#!/bin/bash
H_NAME=$( hostname -f )
LE_SERVICES_SCRIPT_DIR=/usr/lib/acme/hooks
LE_CERTS_DIR=/var/lib/acme/live/$H_NAME
LE_LOG_DIR=/var/log/letsencrypt
PGPOOL2_CERTDIR=/etc/pki/pgpool2
PGPOOL2_KEYFILE=$PGPOOL2_CERTDIR/pgpool2.key
DATE=$( date )
[ ! -d $PGPOOL2_CERTDIR ] && mkdir -p $PGPOOL2_CERTDIR
[ ! -d $LE_LOG_DIR ] && mkdir $LE_LOG_DIR
echo "$DATE" >> $LE_LOG_DIR/pgpool2.log
logger "acme-pgpool-hook: Check if the certificate has been renewed"
cmp ${LE_CERTS_DIR}/privkey ${PGPOOL2_KEYFILE}
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
logger "acme-pgpool-hook: No new cerficate"
echo "acme-pgpool-hook: No new cerficate" >> $LE_LOG_DIR/pgpool2.log
else
logger "acme-pgpool-hook: Copying the key file"
echo "Copy the key file" >> $LE_LOG_DIR/pgpool2.log
/bin/cp -f ${LE_CERTS_DIR}/privkey ${PGPOOL2_KEYFILE}
fi
chmod 440 ${PGPOOL2_KEYFILE}
chown root ${PGPOOL2_KEYFILE}
chgrp postgres ${PGPOOL2_KEYFILE}
logger "acme-pgpool-hook: Reload the PgPoolII service after a letsencrypt execution"
echo "Reload the pgpool2 service" >> $LE_LOG_DIR/pgpool2.log
if [ -x /bin/systemctl ] ; then
{% if ansible_distribution_file_variety == "Debian" %}
systemctl reload pgpool2 >> $LE_LOG_DIR/pgpool2.log 2>&1
{% else %}
systemctl reload pgpool2-{{ psql_version }} >> $LE_LOG_DIR/pgpool2.log 2>&1
{% endif %}
else
service pgpool2 reload >> $LE_LOG_DIR/pgpool2.log 2>&1
fi
logger "acme-pgpool-hook: Done"
echo "Done." >> $LE_LOG_DIR/pgpool2.log
exit 0