1
nginxの仮想ホストで何らかの操作をしているbashスクリプトがあります。 nginxが正しく再ロードされないと、エラーをキャッチする方法を知りたいです(nginx reload
)。nginx reloadでエラーをキャッチ
私はnginx -t
を使用すると思いますが、bashスクリプトでエラーを傍受することはわかりません。
nginxの仮想ホストで何らかの操作をしているbashスクリプトがあります。 nginxが正しく再ロードされないと、エラーをキャッチする方法を知りたいです(nginx reload
)。nginx reloadでエラーをキャッチ
私はnginx -t
を使用すると思いますが、bashスクリプトでエラーを傍受することはわかりません。
彼がリロードするとき0を返す-t nginxのではなく、
hbranciforte# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
hbranciforte# echo $?
0
hbranciforte# vim /etc/nginx/nginx.conf
zsh: suspended vim /etc/nginx/nginx.conf
hbranciforte# nginx -t
nginx: [emerg] unknown directive "siiendfile" in /etc/nginx/nginx.conf:16
nginx: configuration file /etc/nginx/nginx.conf test failed
hbranciforte# echo $?
1
ですから、この
#!/bin/bash
output=$(nginx -t)
reload_code=$?
if [ $reload_code -eq 0 ]; then
echo "conf is correct"
else
echo "conf is not correct"
fi
ような何かを行うことが、-tだけの構成をチェックすることを忘れないでくださいすることができます別の何か、あなたが本当にあなたの設定を再ロードしたい場合は、送信する必要があります
nginx -s reload
#!/bin/bash
output=$(nginx -s reload)
reload_code=$?
if [ $reload_code -eq 0 ]; then
echo "reloaded"
else
echo "could not reload, exit with $reload_code"
fi