Let's encrypt の 更新cronが設定できてなかった

cronに設定したつもりができていなかったので追記。

Amazon Linuxではそもそも更新に使う Certbot はサポートされていない。
そして、cron.d も最初からは入っていない。

昔どうやったんだったけな... と思い出しながら作業。

 

とりあえず Certbot がいるか確認。

$ which certbot
/usr/bin/certbot

$ sudo certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/(conf)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Account registered.
Simulating renewal of an existing certificate for hyogo.dev
Failed to renew certificate hyogo.dev with error: Could not bind TCP port 80 because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/(domain)/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

どうやら certbot コマンドは使えるみたい。
ただ、サイトを公開しながらだと、 80番ポートが使われてるうんぬん。

取り急ぎ、誰も見てないサイトなので構わずhttpdを一旦止めて更新。

--dry-run の結果も良さそうなので、そのまま本番も更新。

 

cronを設定していく。

とはいえ、httpd を毎回止めるのは困る。

調べてみると、
1)certbot renew --apache などapacheのオプションをつける
2)--post-hook オプションを付ける
といった方法がありそう。

 残念ながら、1の方法はAmazon Linuxの場合、CertbotのApacheプラグインを入れるのが面倒くさそう。

2の方法でcronを設定。

$sudo certbot renew --post-hook "systemctl reload httpd"

↑ で更新できているっぽいので、crontabに書いておく。

 

しばらく様子見。