4

I've always used bluepill successfully to daemonize simple Ruby scripts. This time however, I have a script that's also loading a Rails environment so I can access my database connection for the Rails app and its respective models. The bluepill config I use is no different than what I normally do:

   Bluepill.application("myapp", :foreground => true, :log_file => "/tmp/bluepill.log") do |app|
          app.process("myapp_process") do |process|
            process.start_command = "/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby /media/apps/myapp/current/lib/async/myscript.rb"
            process.pid_file = "/media/apps/myapp/current/tmp/pids/myscript.pid"
            process.daemonize = true
            process.stdout = "/var/log/myapp/media.log"
            process.stderr = "/var/log/myapp/media_error.log"
            process.working_dir = "/tmp"
            process.stop_command = "kill -QUIT {{PID}}"
            process.start_grace_time = 15.seconds
          end
    end

The main issue is this error:

Failed to signal process 16096 with code 0: No such process

If I do not load the Rails environment using this:

require File.expand_path("/media/apps/myapp/current/config/environment")

This will work as it does with a bunch of my other scripts. This is the first time I'm trying to daemonize a script that loads the Rails environment, however. I know I can use the ruby gem Daemons to get this to work, but that doesn't do monitoring and bluepill is capable of doing both really well.

Am I missing something obvious here?

gef
  • 7,025
  • 4
  • 41
  • 48
randombits
  • 47,058
  • 76
  • 251
  • 433

4 Answers4

4

Signal code 0 to kill queries to determine if the daemon is receptive to signals. The Bluepill source shows this is done frequently after spawning to check if the daemon process is alive and well.

Since the process is no longer there, it's likely that ruby is dying while loading the environment.

You didn't show your script. I'm guessing that it runs okay from the command line but fails to daemonize. A probable explanation is that there's something in your shell's environment that's missing in the Bluepill process's. Another possibility is access to resources that your interactive shell has, but the headless daemon process does not.

Here's one guess: For the require you gave to work, I believe the RAILS_ENV environment variable must be set. Are you doing that? See for example this note. Perhaps it's better to load using the boot script. See for example the Rails initialization description.

Gene
  • 46,253
  • 4
  • 58
  • 96
3

Did you know you can run a script in the rails environment with rails runner as well? You might want to try that.

I haven't had much luck with bluepill, I had much more success with eye: https://github.com/kostya/eye

You may want to check that out, it has the same syntax as bluepill.

freedrull
  • 2,194
  • 4
  • 21
  • 33
2

Hmm. We tried bluepill for a while but it wasn't helpful in many cases where processes had complex startups. We've been happier recently with 'runit' which has a number of accompanying components (for example chpset to set user, environment etc) that are very helpful. We're using devops tools like chef to set up machines with standard services now and runit was a better fit. But with any of these you need the pid of the running process you care about to be able to receive signals from the monitoring system - it sounds like here the PID you're getting from your start command:

/media/apps/myapp/current/lib/async/myscript.rb

is not the one that stays running - maybe if you post more of that script we can see what's going on, but I'm guessing somewhere it's forking off another process?

0

on this site https://github.com/arya/bluepill/issues/164 I found this information

After some experimentation i found that if you run the commands with --no-privileged flag as well as base dir and logfile flags it works. They're also included in the configuration so it's a bit redundant :/

Commands example: bundle exec bluepill load bluepill/monitorbs.pill --no-privileged --base-dir /xxx/xxx/xxx --logfile /xxx/xxx/xxx/bluepill/bs.log"

Community
  • 1
  • 1
Claudiu
  • 1,469
  • 13
  • 21