- 1. スクリプトの作成
- 2. cron への登録
- 3. 自動更新確認
1. スクリプトの作成
前ページでうまく更新することまで確認できましたので、今度は、スクリプトを作成します。
オプションの意味等は、前ページをご参照ください。
今度は、強制的でなく、証明書に更新が発生しているときのみの更新です。
#!/bin/sh
/usr/local/bin/certbot \
renew \
--standalone \
--pre-hook "/usr/local/etc/rc.d/apache24 stop" \
--post-hook "/usr/local/etc/rc.d/apache24 start"
スクリプトの実行結果
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
Processing /ディレクトリ名/letsencrypt/renewal/www.sing.ne.jp.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal
-------------------------------------------------------------------------------
Processing /ディレクトリ名/letsencrypt/renewal/freebsd.sing.ne.jp.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal
-------------------------------------------------------------------------------
The following certs are not due for renewal yet:
/ディレクトリ名/letsencrypt/live/www.sing.ne.jp/fullchain.pem (skipped)
/ディレクトリ名/letsencrypt/live/freebsd.sing.ne.jp/fullchain.pem (skipped)
No renewals were attempted.
No hooks were run.
-------------------------------------------------------------------------------
うむ、とても満足です。
2. cron への登録
証明書の更新は、1日に2回とのことですが、有効期限が30日をきると更新してくれるらしいので、cron の実行は1日1回でよいかと思います。
「cronでcertbot renewの--force-renewalを使用してはいけない」
というのはとても興味深い記事です。
「cron で --force-renewal を使用しない」というのはあたり前の話ですね。
アクセスする時刻をランダムにするというのも納得しました。
なので perl でディレイをいれて、以下のような設定にしました。
シェルスクリプト名は certbot.h にしています。
0 0 * * * root /usr/local/bin/perl -e 'sleep int(rand(3600))'; /ディレクトリ名/certbot.sh
証明書の有効期限が、前ページの試験で、2018年3月18日まで延びてしまったので、実際に更新できるかどうかは、2018年2月18日に確認することになります。
3. 自動更新確認
でこれを書いているのが 2018年2月17日の朝なのです。
2月が28日までしかないせい?なのかわからないのですが。
どうも今朝、動いたようです。
ブラウザから確認すると有効期限が「2018年5月17日」に更新されていることがわかります。

cron からのメールを確認してみます。(一部伏字)
Saving debug log to /var/log/letsencrypt/letsencrypt.log
-------------------------------------------------------------------------------
Processing /usr/local/etc/letsencrypt/renewal/www.sing.ne.jp.conf
-------------------------------------------------------------------------------
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator standalone, Installer None
Running pre-hook command: /usr/local/etc/rc.d/apache24 stop
Output from apache24:
Stopping apache24.
Waiting for PIDS: 988.
Renewing an existing certificate
Performing the following challenges:
tls-sni-01 challenge for www.sing.ne.jp
tls-sni-01 challenge for freebsd.sing.ne.jp
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/usr/local/etc/letsencrypt/・・・
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Processing /usr/local/etc/letsencrypt/renewal/・・・
-------------------------------------------------------------------------------
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator standalone, Installer None
Pre-hook command already run, skipping: /usr/local/etc/rc.d/apache24 stop
Renewing an existing certificate
Performing the following challenges:
tls-sni-01 challenge for freebsd.sing.ne.jp
Waiting for verification...
Cleaning up challenges
-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/usr/local/etc/letsencrypt/live/freebsd.sing.ne.jp/fullchain.pem
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Processing /usr/local/etc/letsencrypt/renewal/・・・
-------------------------------------------------------------------------------
Cert not yet due for renewal
-------------------------------------------------------------------------------
The following certs are not due for renewal yet:
/usr/local/etc/letsencrypt/live/ns.sing.ne.jp/fullchain.pem (skipped)
Congratulations, all renewals succeeded. The following certs have been renewed:
/usr/local/etc/letsencrypt/live/www.sing.ne.jp/fullchain.pem (success)
/usr/local/etc/letsencrypt/live/freebsd.sing.ne.jp/fullchain.pem (success)
-------------------------------------------------------------------------------
Running post-hook command: /usr/local/etc/rc.d/apache24 start
Output from apache24:
Performing sanity check on apache24 configuration:
Starting apache24.
Error output from apache24:
Syntax OK
最後の方の [Error output from apache24:] に一瞬びっくりしましたが、apache24 からのエラーはなかったってことですな。
で、これを読んでいてはたと気づいたのが、ログのローテーションを設定していなかった?
|