You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Certbot续期脚本通过Cron执行时挂起,手动执行正常的问题求助

Certbot续期脚本通过Cron执行时挂起,手动执行正常的问题求助

大家好,我遇到了一个非常棘手的问题:我写了一个用于Certbot证书续期的脚本,手动执行时一切流程都能顺利完成,但通过Cron定时执行就会莫名挂住,卡在处理证书配置文件的步骤上,想请各位帮忙排查下问题所在。

相关配置与脚本信息

我的续期脚本存放在/home/user/renew.sh,内容如下:

( cd /home/user/website/ && docker compose run --rm certbot renew --dry-run && docker compose kill -s SIGHUP webserver )

我通过sudo crontab -e添加了定时任务,配置为:

*/5 * * * * /home/user/website/renew.sh >> /var/log/cron.log 2>&1

问题现象

Cron执行后,日志会停在以下内容就不再继续输出了:


Processing /etc/letsencrypt/renewal/website.conf


但如果我用普通用户身份手动执行sh renew.sh,整个续期流程就能正常走完,完全没有卡顿或报错。

Docker Compose中Certbot的配置

我的docker-compose里certbot服务的配置如下:

certbot:
    depends_on:
      - webserver
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - data:/var/www/html
      - "/etc/localtime:/etc/localtime:ro"
    command: certonly --webroot --webroot-path=/var/www/html --email admin@website.com --agree-tos --no-eff-email --force-renewal -d web -d www.web

备注:内容来源于stack exchange,提问作者jotyhista

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 08:58:00