使用 Monit 监控自定义守护进程

发布于 2024-12-20 06:45:13 字数 504 浏览 2 评论 0原文

我有一个用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2024-12-27 06:45:13

对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文