Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

setup-certbot: Run hooks, instead of "service nginx reload".

Alex Vandiver0c953f9870a4
diff --git a/puppet/zulip/files/letsencrypt/020-symlink.sh b/puppet/zulip/files/letsencrypt/020-symlink.sh
new file mode 100755
index 00000000000..8a46afe7ca8
--- /dev/null
+++ b/puppet/zulip/files/letsencrypt/020-symlink.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+symlink_with_backup() {
+ if [ -e "$2" ]; then
+ # If the user is setting up our automatic certbot-management on a
+ # system that already has certs for Zulip, use some extra caution
+ # to keep the old certs available.
+ mv -f --backup=numbered "$2" "$2".setup-certbot || true
+ fi
+ ln -nsf "$1" "$2"
+}
+
+if [ -n "${ZULIP_DOMAIN:-}" ]; then
+ CERT_DIR="/etc/letsencrypt/live/$ZULIP_DOMAIN"
+ symlink_with_backup "$CERT_DIR/privkey.pem" /etc/ssl/private/zulip.key
+ symlink_with_backup "$CERT_DIR/fullchain.pem" /etc/ssl/certs/zulip.combined-chain.crt
+fi
diff --git a/puppet/zulip/manifests/profile/app_frontend.pp b/puppet/zulip/manifests/profile/app_frontend.pp
index 16a4a4912a0..8305f91b37b 100644
--- a/puppet/zulip/manifests/profile/app_frontend.pp
+++ b/puppet/zulip/manifests/profile/app_frontend.pp
@@ -35,6 +35,17 @@ class zulip::profile::app_frontend {
# This was renumbered
ensure => absent,
}
+ file { '/etc/letsencrypt/renewal-hooks/deploy/020-symlink.sh':
+ ensure => file,
+ owner => 'root',
+ group => 'root',
+ mode => '0755',
+ source => 'puppet:///modules/zulip/letsencrypt/020-symlink.sh',
+ require => [
+ Package[certbot],
+ File['/etc/letsencrypt/renewal-hooks/deploy'],
+ ]
+ }
file { '/etc/letsencrypt/renewal-hooks/deploy/050-nginx.sh':
ensure => file,
owner => 'root',
diff --git a/scripts/setup/setup-certbot b/scripts/setup/setup-certbot
index a7d997bddbb..7f873a042b0 100755
--- a/scripts/setup/setup-certbot
+++ b/scripts/setup/setup-certbot
@@ -16,7 +16,7 @@ if [ "$EUID" -ne 0 ]; then
fi
method=webroot
-args="$(getopt -o '' --long help,email:,method:,skip-symlink,agree-tos -n "$0" -- "$@")"
+args="$(getopt -o '' --long help,email:,method:,agree-tos -n "$0" -- "$@")"
eval "set -- $args"
agree_tos=()
while true; do
@@ -31,10 +31,6 @@ while true; do
shift
shift
;;
- --skip-symlink)
- skip_symlink=1
- shift
- ;;
--agree-tos)
agree_tos=(--agree-tos)
shift
@@ -109,34 +105,32 @@ if [ ! -t 0 ]; then
default_keep=(--keep-until-expiring)
fi
+# We need to know _which_ domain is Zulip's, in the symlink deploy
+# hook, so we pass this down
+export ZULIP_DOMAIN="$DOMAIN"
+
+# Certbot does not run deploy hooks on new certificates
+# (certbot/certbot#9978) so we will need to fake it if so
+if [ -d "/etc/letsencrypt/live/$DOMAIN/" ]; then
+ needs_hooks=0
+else
+ needs_hooks=1
+fi
+
certbot certonly "${method_args[@]}" \
"${HOSTNAMES[@]}" -m "$EMAIL" \
"${agree_tos[@]}" \
"${default_keep[@]}" \
--no-eff-email
-symlink_with_backup() {
- if [ -e "$2" ]; then
- # If the user is setting up our automatic certbot-management on a
- # system that already has certs for Zulip, use some extra caution
- # to keep the old certs available.
- mv -f --backup=numbered "$2" "$2".setup-certbot || true
+# "certbot certonly" before version 3.2.0 does not run deploy hooks,
+# so we fake running them.
+if [ "$needs_hooks" = "1" ]; then
+ export RENEWED_DOMAINS="$*"
+ if [ "$method" == "webroot" ]; then
+ for deploy_hook in /etc/letsencrypt/renewal-hooks/deploy/*; do
+ "$deploy_hook"
+ done
fi
- ln -nsf "$1" "$2"
-}
-
-if [ -z "$skip_symlink" ]; then
- CERT_DIR=/etc/letsencrypt/live/"$DOMAIN"
- symlink_with_backup "$CERT_DIR"/privkey.pem /etc/ssl/private/zulip.key
- symlink_with_backup "$CERT_DIR"/fullchain.pem /etc/ssl/certs/zulip.combined-chain.crt
fi
-
-# "certbot certonly" does not run deploy hooks, so reload nginx if
-# need be to pick up the new certificate.
-case "$method" in
- webroot)
- service nginx reload
- ;;
-esac
-
echo "Certbot SSL certificate configuration succeeded."