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

53 lines
1.5 KiB
Plaintext
Raw Normal View History

2020-06-03 19:53:13 +02:00
#!/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
if [ -f /etc/default/letsencrypt ] ; then
. /etc/default/letsencrypt
else
echo "No letsencrypt default file" >> $LE_LOG_DIR/pgpool2.log
fi
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. Doing nothing"
exit 0
fi
logger "acme-pgpool-hook: Copying the key file"
2020-06-03 19:53:13 +02:00
echo "Copy the key file" >> $LE_LOG_DIR/pgpool2.log
cp ${LE_CERTS_DIR}/privkey ${PGPOOL2_KEYFILE}
chmod 440 ${PGPOOL2_KEYFILE}
chown root ${PGPOOL2_KEYFILE}
chgrp postgres ${PGPOOL2_KEYFILE}
logger "acme-pgpool-hook: Reload the postgresql service after a certificate renewal"
2020-06-03 19:53:13 +02:00
echo "Reload the pgpool2 service" >> $LE_LOG_DIR/pgpool2.log
if [ -x /bin/systemctl ] ; then
2020-07-30 14:14:39 +02:00
{% if ansible_distribution_file_variety == "Debian" %}
2020-06-03 19:53:13 +02:00
systemctl reload pgpool2 >> $LE_LOG_DIR/pgpool2.log 2>&1
2020-07-30 14:14:39 +02:00
{% else %}
systemctl reload pgpool2-{{ psql_version }} >> $LE_LOG_DIR/pgpool2.log 2>&1
{% endif %}
2020-06-03 19:53:13 +02:00
else
service pgpool2 reload >> $LE_LOG_DIR/pgpool2.log 2>&1
fi
logger "acme-pgpool-hook: Done"
2020-06-03 19:53:13 +02:00
echo "Done." >> $LE_LOG_DIR/pgpool2.log
exit 0