How can I monitor a PHP script with BluePill?
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开发者_StackOverflow中文版/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
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.
精彩评论