使用 Monit 监控自定义守护进程
我有一个用 PHP 编写的守护进程。我使用以下命令来调用守护进程,
php dojobs.php
当我调用该命令时,守护进程无限运行,因为文件 dojobs.php 具有以下代码
while(true)
{
code here
}
我有以下问题:
- 如何使用 Monit (在 CENTOS linux 5.5 上) 服务器进行监控这个守护进程并在失败时重新启动它?
我在守护进程中有以下代码:
exec('nohup sendMail.php > /dev/null 2>&1 & echo $!';, $op);
(我如何确保上面的 nohup 命令正常工作,并且 sendMail.php 文件确实完成其工作?sendMail.php 不是守护进程。它发送一封电子邮件,然后退出。)
非常感谢。
I have a daemon written in PHP. I use the following command to call the daemon
php dojobs.php
when I call that command, the daemon runs infinitely because the file dojobs.php has the following code
while(true)
{
code here
}
I have the following questions:
- How do I use Monit (on a CENTOS linux 5.5) server to monitor this daemon and restart it if it has failed?
I have the following code inside the daemon:
exec('nohup sendMail.php > /dev/null 2>&1 & echo $!';, $op);
(how do I make sure the nohup command above works correctly and that the sendMail.php file actually does its job? The sendMail.php is not a daemon. It sends an email and then quits.)
Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对 Monit 不熟悉,所以无法帮助您。但是,您可以使用进程控制 (pcntl_*()) 扩展来分叉单独的进程并等待它们将状态代码返回到父进程,以便它能够执行,而不是调用
exec()
了解工作是否已成功完成。Not familiar with Monit, so can't help you with that. But instead of calling
exec()
you can use the Process Control (pcntl_*()) extension to fork separate processes and wait for them to return a status code to the parent process, in order for it to know if the job has been successfuly completed or not.