这是我的第一篇文章,请耐心等待我!
我试图创建检查服务是否无法访问的脚本(http错误代码),然后Monit应该重启程序(预览服务)。 Monit以用户“spark”运行。
这是phantomjs-check.sh代码:
#!/bin/bash
# source: /opt/monit/bin/phantomjs-check.sh
url="localhost:9001/preview/phantomjs"
response=$(curl -sL -w "%{http_code}\\n" $url | grep 200)
if [ "$response" = "}200" ]
then
echo "-= Toimii!!!! =-"
exit 1
else
echo "-= RiKKi!!!! =-"
exit 0
fi
[root@s-preview-1 bin]#
如果我手动终止预览服务并运行该脚本,我会得到退出代码0,这应该是如何工作的。
在Monit我有以下conf:
check program phantomjs with path "/opt/monit/bin/phantomjs-check.sh"
if status = 0 then exec "/opt/monit/bin/testi.sh"
目前我添加了一些日志记录,这是test.sh代码:
#!/bin/sh
# source: /opt/monit/bin/testi.sh
############# Added this for loggin purposes ############
#########################################################
dt=$(date '+%d/%m/%Y %H:%M:%S');
echo Testi.sh run at $dt >> /tmp/testi.txt
# Original part of the script
sudo bash /opt/previewservice/preview-service.sh start
在/ etc / sudoers文件中我有一行:
spark ALL=(ALL) NOPASSWD: /opt/previewservice/preview-service.sh
此命令适用于cli,它启动/重启预览服务。我可以手动运行“testi.sh”脚本作为spark [spark@s-preview-1 bin]$ ./testi.sh
并且它按预期工作,但即使是Monit也会获得服务已关闭但无法启动的信息。
$ cat /tmp/testi.txt
Testi.sh run at 05/01/2018 10:30:04
Testi.sh run at 05/01/2018 10:31:04
Testi.sh run at 05/01/2018 10:31:26
$ cat /tmp/previews.txt
(此行由preview-service.sh启动脚本创建,因此已运行。
File created 05/01/2018 09:26:44
********************************
Preview-service.sh run at 05/01/2018 10:31:26
tail -f -n 1000 /opt/monit/logfile
显示以下
[EET Jan 5 10:29:04] error : 'phantomjs' '/opt/monit/bin/phantomjs-check.sh' failed with exit status (0) -- -= RiKKi!!!! =-
[EET Jan 5 10:29:04] info : 'phantomjs' exec: /opt/monit/bin/testi.sh
[EET Jan 5 10:30:04] error : 'phantomjs' '/opt/monit/bin/phantomjs-check.sh' failed with exit status (0) -- -= RiKKi!!!! =-
[EET Jan 5 10:30:04] info : 'phantomjs' exec: /opt/monit/bin/testi.sh
[EET Jan 5 10:31:04] error : 'phantomjs' '/opt/monit/bin/phantomjs-check.sh' failed with exit status (0) -- -= RiKKi!!!! =-
[EET Jan 5 10:31:04] info : 'phantomjs' exec: /opt/monit/bin/testi.sh
[EET Jan 5 10:32:04] error : 'phantomjs' '/opt/monit/bin/phantomjs-check.sh' failed with exit status (0) -- -= RiKKi!!!! =-
[EET Jan 5 10:32:04] info : 'phantomjs' exec: /opt/monit/bin/testi.sh
[EET Jan 5 10:33:04] info : 'phantomjs' status succeeded
当我将testi.sh脚本作为火花运行而没有冒充时,最后一个状态成功了。
我接下来应该尝试什么提示?我感谢所有帮助!
答案 0 :(得分:0)
Monit通常在 root 用户上运行。是你的情况吗?如果是的话,你可能不需要sudo部分。
在关于你在Monit之外而不是从Monit工作的脚本之后,Monit有了自己的 PATH 环境变量,它非常小。建议将脚本/ binairies的完整路径写为:
df.applymap(lambda x: np.nan if x=='NULL' else x)