我使用系统守护进程 pear 类编写了一个 php 守护进程。
当 monit 出现故障时,如何使用它来重新启动它?
我的 monit 配置文件中有以下代码:
check process merge with pidfile /var/www/merge/merge.pid
group 1000
start program = "/etc/init.d/merge start"
stop program = "/etc/init.d/merge stop"
IF CHANGED PID then restart
我的目标是,如果守护进程失败(由于错误而停止运行),我希望 monit 让它重新开始运行。
答案1
我会这样做并将 ANYTHING_IN_CAPS 更改为您的信息:
set daemon 120
set logfile syslog facility log_daemon
set mailserver YOUR_MAIL_SERVER
set alert YOUR_EMAIL_ADDRESS
mail-format {
from: EMAIL_FROM
reply-to: EMAIL_FROM
subject: $SERVICE $EVENT at $DATE
message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
Your watch guard,
monit
}
set httpd port 2812 and
use address localhost
allow localhost
check process merge
with pidfile /var/www/merge/merge.pid
start program = "/etc/init.d/merge start"
stop program = "/etc/init.d/merge stop"
这还允许您发出 monit 命令,例如:
monit summary
然后您可以看到当前状态,并且当重新启动时您将能够收到电子邮件。