Files
openresty-gateway/scripts/renew-certs.sh
2026-05-18 22:32:08 +08:00

27 lines
708 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env sh
set -eu
# 日常续期用:
# certbot renew 会自己判断证书是否快过期;没到续期时间不会真正重签。
# renew 成功或无须续期后,重载 OpenResty让已经更新的证书生效。
ROOT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)"
cd "$ROOT_DIR"
. "$ROOT_DIR/scripts/lib-compose.sh"
echo "按需续期证书..."
compose run --rm --entrypoint certbot certbot \
renew --webroot -w /var/www
echo "重载 OpenResty 以使用续期后的证书..."
if compose exec -T openresty openresty -s reload; then
echo "OpenResty 已重载。"
else
echo "重载失败,改为重启 OpenResty..."
compose restart openresty
fi
echo "完成。"