[英]Nginx and Phusion Passenger running but passenger-status showing 0 processes running
[英]Get nginx running status as bool
我想为我的脚本设置一个 nginx-status-bool 来检查它是否正在运行(真)或不运行(假)。 如果我使用“sudo service nginx 状态”,我会得到全部信息,但我想要一种只得到真/假的方法。
systemctl
命令遵循退出代码的LSB 语义。
具体来说, systemctl status nginx
如果程序未运行,将退出代码3
,如果程序正在运行,将退出代码0
。
启动程序并获取其退出代码应该相当简单,例如:
<?php
exec('systemctl status nginx', $out, $exit_code);
if (0 == $exit_code) {
echo 'NGINX is running';
} elseif (3 == $exit_code) {
echo 'NGINX is stopped';
}
PS您不必使用sudo
运行systemctl
。 它应该适用于非特权用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.