【问题标题】:How can I monitor a PHP script with BluePill?如何使用 BluePill 监控 PHP 脚本?
【发布时间】:2011-03-18 16:51:19
【问题描述】:

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

是否甚至可以使用 BluePill 来监控/守护 PHP 脚本?我通过 Google 找到的所有示例配置文件都是针对 Rails 应用程序的。我更喜欢 Ruby 而不是 PHP,并且想尝试其他的东西而不是 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

【问题讨论】:

  • 您的工作脚本有错误吗?如果通过 CLI 手动执行会发生什么?
  • 另外请记住,CLI 使用的 CWD 与通过 BluePill 作为守护程序运行时的 CWD 不同,因此如果您使用的是相对目录,请进行相应调整。 :)
  • 手动启动进程可以正常工作,并正确地从队列中抓取作业并完成任务,所以我相信工作脚本很好。此外,我过去也学会了在 CLI 脚本中使用完整路径的艰难方法,所以我确保现在就这样做。
  • 明白了,好的。你可以粘贴你的工人(或任何一个)吗?
  • 另外,你能知道它是否真的在/tmp/ 中创建了你的.pid

标签: php ruby beanstalkd bluepill


【解决方案1】:

为了后代:

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

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

【讨论】:

  • 致其他阅读本文的人:请参阅我的问题中 cmets 的原始线程,了解 CLI 答案中 CWD 的完整上下文
猜你喜欢
  • 2013-09-22
  • 1970-01-01
  • 2011-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多