|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -### BEGIN INIT INFO |
4 | | -# Provides: LETSENCRYPT RENEW HOOK SCRIPT |
5 | | -# Required-Start: $local_fs $network |
6 | | -# Required-Stop: $local_fs |
7 | | -# Default-Start: 2 3 4 5 |
8 | | -# Default-Stop: 0 1 6 |
9 | 3 | # Short-Description: LETSENCRYPT RENEW HOOK SCRIPT |
10 | 4 | # Description: Taken from LE4ISPC code. To be used to update ispserver.pem automatically after ISPConfig LE SSL certs are renewed and to reload / restart important ISPConfig server services |
11 | | -### END INIT INFO |
12 | 5 |
|
13 | 6 | ## If you need a custom hook file, create a file with the same name in |
14 | 7 | ## /usr/local/ispconfig/server/conf-custom/scripts/ |
15 | 8 | ## |
16 | 9 | ## End the file with 'return 124' to signal that this script should not terminate. |
17 | | -if [ -e "/usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_renew_hook.sh" ] ; then |
18 | | - . /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_renew_hook.sh |
19 | | - ret=$? |
20 | | - if [ $ret != 124 ]; then exit $ret; fi |
| 10 | +if [ -e "/usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_renew_hook.sh" ]; then |
| 11 | + . /usr/local/ispconfig/server/conf-custom/scripts/letsencrypt_renew_hook.sh |
| 12 | + ret=$? |
| 13 | + if [ $ret != 124 ]; then exit $ret; fi |
21 | 14 | fi |
22 | 15 |
|
23 | 16 | hostname=$(hostname -f) |
24 | | -if [ -d "/usr/local/ispconfig/server/scripts/${hostname}" ] ; then |
25 | | - lelive="/usr/local/ispconfig/server/scripts/${hostname}" ; |
26 | | -elif [ -d "/root/.acme.sh/${hostname}" ] ; then |
27 | | - lelive="/root/.acme.sh/${hostname}" ; |
28 | | -else |
29 | | - lelive="/etc/letsencrypt/live/${hostname}" ; |
| 17 | + |
| 18 | +# If you want to manually execute letsencrypt_renew_hook.sh, call it with the SUCCESS environment variable set. |
| 19 | +# E.g. like this: "SUCCESS=1 letsencrypt_renew_hook.sh" |
| 20 | +# Then we assume that the certificate is there and do the post-processing. |
| 21 | +SUCCESS=${SUCCESS:-} |
| 22 | + |
| 23 | +# acme.sh defines/exports the environment variables |
| 24 | +# CERT_PATH, CERT_KEY_PATH, CA_CERT_PATH, CERT_FULLCHAIN_PATH and Le_Domain (main cert domain) |
| 25 | +# for all hooks |
| 26 | +if [ -f "$CERT_KEY_PATH" ] && [[ "${Le_Domain:-}" == "$hostname" ]]; then |
| 27 | + SUCCESS=acme.sh |
| 28 | + echo "$(/bin/date)" "Reconfigure and reload services after $hostname certificate issuing/renewal via acme.sh" >>/var/log/ispconfig/ispconfig.log |
| 29 | +# certbot defines/exports the environment variables |
| 30 | +# RENEWED_DOMAINS (all cert domains space separated) and RENEWED_LINEAGE (directory in /etc/letsencrypt/live) |
| 31 | +# for the renew/deploy hook |
| 32 | +elif [ -d "$RENEWED_LINEAGE" ] && [[ "$RENEWED_DOMAINS " == "$hostname "* ]]; then |
| 33 | + SUCCESS=certbot |
| 34 | + echo "$(/bin/date)" "Reconfigure and reload services after $hostname certificate issuing/renewal via certbot" >>/var/log/ispconfig/ispconfig.log |
30 | 35 | fi |
31 | 36 |
|
32 | | -if [ -d "$lelive" ]; then |
33 | | - cd /usr/local/ispconfig/interface/ssl; ibak=ispserver.*.bak; ipem=ispserver.pem; icrt=ispserver.crt; ikey=ispserver.key |
34 | | - if ls $ibak 1> /dev/null 2>&1; then rm $ibak; fi |
35 | | - if [ -e "$ipem" ]; then mv $ipem $ipem-$(date +"%y%m%d%H%M%S").bak; cat $ikey $icrt > $ipem; chmod 600 $ipem; fi |
36 | | - pureftpdpem=/etc/ssl/private/pure-ftpd.pem; if [ -e "$pureftpdpem" ]; then chmod 600 $pureftpdpem; fi |
37 | | - # For Red Hat, Centos or derivatives |
38 | | - if which yum &> /dev/null 2>&1 ; then |
39 | | - if ( rpm -q pure-ftpd ); then service pure-ftpd restart; fi |
40 | | - if ( rpm -q monit ); then service monit restart; fi |
41 | | - if ( rpm -q postfix ); then service postfix restart; fi |
42 | | - if ( rpm -q dovecot ); then service dovecot restart; fi |
43 | | - if ( rpm -q mysql-server ); then service mysqld restart; fi |
44 | | - if ( rpm -q mariadb-server ); then service mariadb restart; fi |
45 | | - if ( rpm -q MariaDB-server ); then service mysql restart; fi |
46 | | - if ( rpm -q nginx ); then service nginx restart; fi |
47 | | - if ( rpm -q httpd ); then service httpd restart; fi |
48 | | - # For Debian, Ubuntu or derivatives |
49 | | - elif apt-get -v >/dev/null 2>&1 ; then |
50 | | - if [ $(dpkg-query -W -f='${Status}' pure-ftpd-mysql 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service pure-ftpd-mysql restart; fi |
51 | | - if [ $(dpkg-query -W -f='${Status}' monit 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service monit restart; fi |
52 | | - if [ $(dpkg-query -W -f='${Status}' postfix 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service postfix restart; fi |
53 | | - if [ $(dpkg-query -W -f='${Status}' dovecot-imapd 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service dovecot restart; fi |
54 | | - if [ $(dpkg-query -W -f='${Status}' mysql 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service mysql restart; fi |
55 | | - if [ $(dpkg-query -W -f='${Status}' mariadb 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service mysql restart; fi |
56 | | - if [ $(dpkg-query -W -f='${Status}' nginx 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service nginx restart; fi |
57 | | - if [ $(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed") -eq 1 ]; then service apache2 restart; fi |
| 37 | +if [ -n "$SUCCESS" ]; then |
| 38 | + if cd /usr/local/ispconfig/interface/ssl; then |
| 39 | + ipem=ispserver.pem |
| 40 | + icrt=ispserver.crt |
| 41 | + ikey=ispserver.key |
| 42 | + if ls ispserver.*.bak &>/dev/null; then |
| 43 | + rm ispserver.*.bak |
58 | 44 | fi |
59 | | -else echo `/bin/date` "Your Lets Encrypt SSL certs path for your ISPConfig server FQDN is missing.$line" >> /var/log/ispconfig/ispconfig.log; fi |
| 45 | + if [ -e "$ipem" ]; then |
| 46 | + mv $ipem "$ipem-$(date +"%y%m%d%H%M%S").bak" |
| 47 | + cat $ikey $icrt >$ipem |
| 48 | + chmod 600 $ipem |
| 49 | + fi |
| 50 | + fi |
| 51 | + pureftpdpem=/etc/ssl/private/pure-ftpd.pem |
| 52 | + if [ -e "$pureftpdpem" ]; then chmod 600 $pureftpdpem; fi |
| 53 | + # For Red Hat, Centos or derivatives |
| 54 | + if which yum &>/dev/null 2>&1; then |
| 55 | + if rpm -q pure-ftpd; then service pure-ftpd restart; fi |
| 56 | + if rpm -q monit; then service monit restart; fi |
| 57 | + if rpm -q postfix; then service postfix restart; fi |
| 58 | + if rpm -q dovecot; then service dovecot restart; fi |
| 59 | + if rpm -q mysql-server; then service mysqld restart; fi |
| 60 | + if rpm -q mariadb-server; then service mariadb restart; fi |
| 61 | + if rpm -q MariaDB-server; then service mysql restart; fi |
| 62 | + if rpm -q nginx; then service nginx restart; fi |
| 63 | + if rpm -q httpd; then service httpd restart; fi |
| 64 | + # For Debian, Ubuntu or derivatives |
| 65 | + elif apt-get -v >/dev/null 2>&1; then |
| 66 | + if [ "$(dpkg-query -W -f='${Status}' pure-ftpd-mysql 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service pure-ftpd-mysql restart; fi |
| 67 | + if [ "$(dpkg-query -W -f='${Status}' monit 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service monit restart; fi |
| 68 | + if [ "$(dpkg-query -W -f='${Status}' postfix 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service postfix restart; fi |
| 69 | + if [ "$(dpkg-query -W -f='${Status}' dovecot-imapd 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service dovecot restart; fi |
| 70 | + if [ "$(dpkg-query -W -f='${Status}' mysql 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service mysql restart; fi |
| 71 | + if [ "$(dpkg-query -W -f='${Status}' mariadb 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service mysql restart; fi |
| 72 | + if [ "$(dpkg-query -W -f='${Status}' nginx 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service nginx restart; fi |
| 73 | + if [ "$(dpkg-query -W -f='${Status}' apache2 2>/dev/null | grep -c "ok installed")" -eq 1 ]; then service apache2 restart; fi |
| 74 | + fi |
| 75 | +else |
| 76 | + echo "$(/bin/date)" "Your Lets Encrypt SSL certs path for your ISPConfig server FQDN is missing." >>/var/log/ispconfig/ispconfig.log |
| 77 | +fi |
0 commit comments