#!/bin/bash

LOG_FILE="/var/log/certbot-renew.log"
DATE=$(date '+%Y-%m-%d %H:%M:%S')

echo "[$DATE] 开始检查证书续期" >> $LOG_FILE

certbot renew --pre-hook "systemctl stop nginx" --post-hook "systemctl start nginx" >> $LOG_FILE 2>&1

if [ $? -eq 0 ]; then
    echo "[$DATE] 证书续期检查完成" >> $LOG_FILE
else
    echo "[$DATE] 证书续期失败" >> $LOG_FILE
fi
