53 lines
1.5 KiB
Django/Jinja
53 lines
1.5 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
|
|
|
|
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"
|
|
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"
|
|
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
|
|
|