如果服务未运行,我必须使用Nagios Server在远程服务器(192.168.1.105)上检查服务是否正在运行,然后我想运行此服务。
我正在使用带有NRPE的Nagios 。
为此,我使用下面的脚本
#!/bin/bash
if pgrep -f "index.js" >/dev/null; then
echo "index.js is Running."
exit 0
else
echo "index.js is Stopped."
exit 2
fi
借助上述脚本,我可以检查服务是否正在运行。
但我的问题是,如果服务没有运行,那我怎么能运行这项服务。
对于远程服务器上的运行服务,我只需编辑上面提到的服务,如下所述
#!/bin/bash
if pgrep -f "index.js" >/dev/null; then
echo "index.js is Running."
exit 0
else
echo "index.js is Stopped."
servicestatus=$(ssh root@192.168.1.105 nohup node /root/demo/index.js > index.log &)
echo "$servicestatus"
exit 2
fi
但这不适合我。