php5-fpm:bash脚本在重启之前检查configuration

我写了一个脚本来在Nginx上创build新的虚拟主机。 该脚本创build了Ningx vhostconfiguration文件,vhost用户和dirs,php-fpm池文件。

在脚本的最后,我想在重新启动php-fpm之前检查configuration是否正常。 对于Apache,我做apachectl graceful ,但是有可能做类似于php5-fpm -t

从手册:

  --test -t Test FPM configuration file and exit If called twice (-tt), the configuration is dumped before exiting. 

如果configuration有效, php5-fpm -t应该以代码0退出,否则退出代码为非零。 你的脚本应该这样做:

 if ! php5-fpm -t; then echo "php5-fpm configuration is invalid" exit 1 fi 

但是,我对我的configuration进行了一些修改,而这些修改没有被视为无效,所以YMMV。