ISPConfig-Stuff/le_services_restart.sh

65 lines
1.7 KiB
Bash

#!/bin/sh
### BEGIN INIT INFO
# Provides: LE SERVICES CERT AUTO UPDATER
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: LE SERVICES CERT AUTO UPDATER
# Description: Restart services automatically when a new Let's Encrypt certificate is issued.
### END INIT INFO
# postfix
domain=SERVER.EXAMPLE.COM
certfile=$(mktemp)
keyfile=$(mktemp)
if [ -e "/etc/letsencrypt/live/$domain/fullchain.pem" ]; then
cat /etc/letsencrypt/live/$domain/fullchain.pem > $certfile
cat /etc/letsencrypt/live/$domain/privkey.pem > $keyfile
elif [ -e "/root/.acme.sh/$domain/$domain.cer" ]; then
cat /root/.acme.sh/$domain/ca.cer > $certfile
cat /root/.acme.sh/$domain/$domain.cer >> $certfile
cat /root/.acme.sh/$domain/$domain.key > $keyfile
else
exit 1
fi
FILE=/etc/postfix/main.cf
if [ -f "$FILE" ]; then
systemctl restart influxd
fi
# dovecot
FILE=/etc/dovecot/dovecot.conf
if [ -f "$FILE" ]; then
systemctl restart dovecot
fi
# pro-tftp
FILE=/etc/pure-ftpd/pure-ftpd.conf
if [ -f "$FILE" ]; then
cat $certfile > /etc/ssl/private/pure-ftpd.pem
cat $keyfile >> /etc/ssl/private/pure-ftpd.pem
systemctl restart pure-ftpd-mysql.service
fi
# influxdb
FILE=/etc/influxdb/influxdb.pem
if [ -f "$FILE" ]; then
cat $certfile > /etc/influxdb/influxdb.pem
cat $keyfile > /etc/influxdb/influxdb.key
systemctl restart influxd
fi
# coturn
FILE=/usr/local/etc/turn_server_cert.pem
if [ -f "$FILE" ]; then
cat $certfile > /usr/local/etc/turn_server_cert.pem
cat $keyfile > /usr/local/etc/turn_server_pkey.pem
chown turnserver /usr/local/etc/turn_server*
systemctl restart coturn
fi
rm $certfile
rm $keyfile