Let’s Encryptで証明書が更新されない際の対処

こんにちは、mi2yo4です。

最近は朝晩のバイク通勤が寒さで辛くなってきました。もうちょっと暖かくなって欲しいものですね。

さて今日はLet’s Encryptのその後について書いてみたいと思います。

何故か証明書が更新されない

以前のエントリでお手軽にWebサーバのサーバ証明書を取得してみました。

Let’s Encryptの証明書は3ヶ月に一回、更新する必要が出てきます。

最初は手作業で更新作業を行っていましたが、さすがにルーチンワークなので、cronで実行して頂くように変更。

# crontab -e

00 05 01 * * /usr/local/certbot/certbot-auto renew --pre-hook "service httpd stop" --post-hook "service httpd start"

これで楽できる~、と思ったのです。

が、何故か「サーバ証明書が後少しで期限切れだよ(超意訳)」というメールが来てしまいましたorz

サーバログを調べてみた

まず考えられるのはcrontabの記述のミス。
パスが通っていないから実行されない、という事を考えてみましたが、ログにはcronが正しく実行されているようでした。

実行してみる

記述ミスは無さそうなので、crontabで書かれているコマンドをそのままコピペして試しに実行してみます。

すると…

yum updateが実行されて、パッケージを更新するかどうかという所でユーザー入力状態となりました。
ひょっとしたらここが問題なのかも知れません。

「certbot-auto –help」でヘルプを見てみます。

Usage: certbot-auto [OPTIONS]
A self-updating wrapper script for the Certbot ACME client. When run, updates
to both this script and certbot will be downloaded and installed. After
ensuring you have the latest versions installed, certbot will be invoked with
all arguments you have provided.

Help for certbot itself cannot be provided until it is installed.

  --debug                                   attempt experimental installation
  -h, --help                                print this help
  -n, --non-interactive, --noninteractive   run without asking for user input
  --no-self-upgrade                         do not download updates
  --os-packages-only                        install OS dependencies and exit
  -q, --quiet                               provide only update/error output
  -v, --verbose                             provide more output

All arguments are accepted and forwarded to the Certbot client when run.

上記で言えば、-nオプションを付ければ上手く行くかも知れません。
早速下のように-nオプションをつけて実行してみました。

# /usr/local/certbot/certbot-auto renew -n --pre-hook "service httpd stop" --post-hook "service httpd start"

今度はうまく行ったようです。

crontabにも同様にオプションを追加しておきましょう。

# crontab -e

00 05 01 * * /usr/local/certbot/certbot-auto renew -n --pre-hook "service httpd stop" --post-hook "service httpd start"

まとめ

今回はapacheまわりのモジュールが少し古かったようで、それと併せて証明書も更新されました。
という事は、apacheの更新についてもcertbotスクリプトに任せても良いのかも知れませんね。

今日はちょっと勉強になりました。
それではまた!