0

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
grafikchaos
  • 555
  • 1
  • 4
  • 13
  • Does your worker script have errors? What happens if you execute it manually via CLI? – mway Mar 18 '11 at 16:52
  • Also 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. :) – mway Mar 18 '11 at 16:54
  • starting the process manually works fine and correctly grabs the jobs from the queue and completes the tasks so I believe the worker script is fine. Also I've learned the hard way in the past to use full paths in CLI scripts so I make sure I do that now. – grafikchaos Mar 18 '11 at 16:58
  • Gotcha, okay. Can you pastebin (or whichever) your worker? – mway Mar 18 '11 at 17:05
  • Also, are you able to tell if it's actually creating your `.pid` in `/tmp/`? – mway Mar 18 '11 at 17:05
  • Ok, I think you're original suggestion about checking the CWD within the CLI is correct. My worker is defining constants based off the relative location of the file so I think I just need to change my BluePill script to go into the current release directory to get to the worker script. For reference, [here's the pastebin of WorkerThumbnail.php script](http://pastebin.com/uRNZXQ35) – grafikchaos Mar 18 '11 at 17:37
  • OK, confirmed that it was just a relative path issue and how my BluePill script was calling it. It's now up and running so thanks for the help! The fix was to change the **shared** directory to **current** directory in `process.start_command` argument. – grafikchaos Mar 18 '11 at 17:57
  • @mway - if you want to submit your CWD comment as the answer I'll gladly accept it as the correct answer to my original question – grafikchaos Mar 18 '11 at 18:01

1 Answers1

0

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.

mway
  • 4,334
  • 3
  • 26
  • 37
  • to other peeps reading this: see the original thread of comments in my question for full context of CWD in the CLI answer – grafikchaos Mar 18 '11 at 18:04