如何使用 BluePill 监控 PHP 脚本?
我创建了一个 Beanstalkd 工作脚本(使用 Pheanstalk 库) 来处理上传时图像的缩略图,并希望实现 BluePill 来监视/守护工作脚本,但 BluePill 无法启动该进程,只是在启动和关闭之间循环。
是否可以使用 BluePill 来监控/守护 PHP 脚本?我通过 Google 找到的所有示例配置文件都是针对 Rails 应用程序的。与 PHP 相比,我更喜欢 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
I've created a Beanstalkd worker script (using Pheanstalk library) to handle the thumb nailing of images when uploaded and wanted to implement BluePill to monitor/daemonize the worker script but the BluePill fails to start the process and just cycles between starting and going down.
Is it even possible to use BluePill to monitor/daemonize a PHP script? All the example config files I found through Google were for Rails apps. I prefer Ruby over PHP and wanted to try something other than supervisord because quite frankly I liked the BluePill syntax better.
Here's my BluePill script:
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
When I run the BluePill script in the foreground then I see the following output repeated over and over until I manually kill the process
[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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于后代:
请记住,CLI 使用中的 CWD 与通过 BluePill 作为守护程序运行时的 CWD 不同,因此,如果您使用相对目录,请进行相应调整。
如果这不是真正的问题,请随时更新。
For posterity:
Bear in mind that your CWD from CLI usage will be different than when it is run as a daemon via BluePill, so if you're using relative directories, adjust accordingly.
Feel free to update if that ends up not being the real issue.