The error was: NoInstallationError(“Could not find a usable ‘nginx’ binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.”,) の解決方法

The error was: NoInstallationError(“Could not find a usable ‘nginx’ binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.”,) というエラーが発生したときの解決方法をご紹介します。

Let’s Encrypt

背景 crontab で certbot-auto renew –nginx がエラー

Let’s Encrypt の SSL 証明書を certbot と crontab で自動更新する設定方法 にて設定した処理がエラーで失敗していました。

解決方法 PATH を適切に設定する

cron の実行結果のログに以下のようなエラーメッセージが出力されていました。

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/codenote.net.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Non-interactive renewal: random delay of 18.66088887793885 seconds
Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",)
Attempting to renew cert (codenote.net) from /etc/letsencrypt/renewal/codenote.net.conf produced an unexpected error: The nginx plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.",). Skipping.
All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/codenote.net/fullchain.pem (failure)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/codenote.net/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1 renew failure(s), 0 parse failure(s)

The error was: NoInstallationError(“Could not find a usable ‘nginx’ binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.”,) のエラーメッセージ通り、 PATH が適切に設定されてないのが問題なので crontab の PATH を見直しましょう。

$ crontab -l
PATH=/usr/local/bin:/bin:/usr/bin

$ which nginx
/usr/sbin/nginx

という状態だったので、crontab を以下のように PATH に /usr/sbin も追加してあげれば OK です。

$ crontab -l
PATH=/usr/local/bin:/usr/sbin:/bin:/usr/bin

以上、crontab の PATH 設定漏れ問題に直面した、現場からお送りしました。

参考情報