如何使用BluePill监控PHP脚本?

时间:2011-03-18 16:51:20

标签: php ruby beanstalkd bluepill

我创建了一个Beanstalkd工作人员脚本(使用Pheanstalk library)来处理上传时图像的缩略图,并希望实现BluePill来监视/守护工作脚本但是BluePill无法启动该过程,只是在开始和停止之间循环。

甚至可以使用BluePill来监控/守护PHP脚本吗?我通过Google找到的所有示例配置文件都是针对Rails应用程序的。我更喜欢Ruby而不是supervisord,因为坦白说我更喜欢BluePill语法。

这是我的BluePill脚本:

Bluepill.application("WorkerThumnail") do |app|
  app.process("thumbnail_watch") do |process|
    process.start_command = "/usr/local/bin/php /var/www/example.com/staging/shared/tasks/WorkerThumbnail.php"
    process.pid_file = "/tmp/beanstalk_thumbnail_worker.pid"
    process.daemonize = true

    process.start_grace_time = 3.seconds
    process.stop_grace_time = 5.seconds
    process.restart_grace_time = 8.seconds

    ###########################################
    # Memory and CPU Usage checks to make sure 
    # we don't have a runaway
    ###########################################

    # Check every 20 seconds to make the CPU usage is below 5%; 
    # if 3 out of 5 checks failed then restart the process
    process.checks :cpu_usage, :every => 20.seconds, :below => 5, :times => [3,5]

    # Check every 10 seconds to make the Memory usage is below 100 MB; 
    # if 3 out of 5 checks failed then restart the process
    process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
  end 
end

当我在前台运行BluePill脚本时,我看到以下输出一遍又一遍地重复,直到我手动终止进程

[warning]: [WorkerThumnail:thumbnail_watch] Executing start command: /usr/local/bin/php 
/var/www/example.com/staging/shared/tasks/WorkerThumbnail.php
[info]: [WorkerThumnail:thumbnail_watch] Going from down => starting
[info]: [WorkerThumnail:thumbnail_watch] Going from starting => down
[warning]: [WorkerThumnail:thumbnail_watch] Executing start command: /usr/local/bin/php /var/www/example.com/staging/shared/tasks/WorkerThumbnail.php
[info]: [WorkerThumnail:thumbnail_watch] Going from down => starting
[info]: [WorkerThumnail:thumbnail_watch] Going from starting => down
[warning]: [WorkerThumnail:thumbnail_watch] Executing start command: /usr/local/bin/php /var/www/example.com/staging/shared/tasks/WorkerThumbnail.php
[info]: [WorkerThumnail:thumbnail_watch] Going from down => starting
[info]: [WorkerThumnail:thumbnail_watch] Going from starting => down
[warning]: [WorkerThumnail:thumbnail_watch] Executing start command: /usr/local/bin/php /var/www/example.com/staging/shared/tasks/WorkerThumbnail.php
[info]: [WorkerThumnail:thumbnail_watch] Going from down => starting
[info]: [WorkerThumnail:thumbnail_watch] Going from starting => down

1 个答案:

答案 0 :(得分:0)

后人:

请记住,CLI使用的CWD与通过BluePill作为守护程序运行时的CWD不同,因此如果您使用的是相对目录,请相应调整。

如果最终不是真正的问题,请随时更新。