2

I have Bluepill setup to monitor my delayed_job processes.

On my production server, I use RVM installed in the user's home folder (username is deploy). My app's gems are installed in its own project-specific gemset. So, the bluepill gem and its corresponding binary are installed within the ~/.rvm/.... folder.

When I deploy my app using capistrano, I want bluepill to be stopped and started, so my DJs get restarted. I am looking at the instructions for the capistrano recipe here.

I think my RVM-compliant bluepill tasks have to be like the following:

# Bluepill related tasks
after 'deploy:start', 'bluepill:start'
after 'deploy:stop', 'bluepill:quit'
after 'deploy:restart', 'bluepill:quit', 'bluepill:start'

namespace :bluepill do
  desc 'Stop processes that bluepill is monitoring and quit bluepill'
  task :quit, :roles => [:app] do
    run "cd #{current_path}; sudo bluepill #{application}_#{rails_env} stop"
    run "cd #{current_path}; sudo bluepill #{application}_#{rails_env} quit"
    sleep 5
  end

  desc 'Load bluepill configuration and start it'
  task :start, :roles => [:app] do
    run "cd #{current_path}; sudo bluepill load #{current_path}/config/server/#{rails_env}/delayed_job.bluepill"
  end

  desc 'Prints bluepills monitored processes statuses'
  task :status, :roles => [:app] do
    run "cd #{current_path}; sudo bluepill #{application}_#{rails_env} status"
  end
end

I haven't tested the above yet.

What I am wondering is: what should I put in my sudoers file to allow the deploy user run just these bluepill related commands as root without a password? On this page they have mentioned this:

deploy ALL=(ALL) NOPASSWD: /usr/local/bin/bluepill

But the path to the bluepill binary would be different in my case. And it would be different for different projects, because of project-specific gemsets. Should I be mentioning each of the binary paths or is there a better way of handling this?

Anjan
  • 1,613
  • 1
  • 19
  • 25

1 Answers1

2

use wrappers and aliases:

namespace :bluepill do
  task :setup do
    run "rvm alias create #{application} #{rvm_ruby_name_evaluated}"
    run "rvm wrappers #{application} --no-links bluepill"
  end
end

so after this task bluepill is available via #{rvm_path}/wrappers/#{application}/bluepill which will be always the same even if you change ruby version, so it can be added to sudoers for preserving path:

deploy ALL=(ALL) NOPASSWD: /home/my_user/.rvm/wrappers/my_app/bluepill

and then the tasks can use:

sudo #{rvm_path}/wrappers/#{application}/bluepill ...

it is important to note here that the wrapper takes care of loading rvm environment because it was lost by invocation of sudo ... but this is just a detail ;)

mpapis
  • 52,729
  • 14
  • 121
  • 158
  • This still creates one bluepill binary per application, right? If I have another app, that app's bluepill would have to be added to the sudoers file separately, right? And in the `setup` task you have given above, don't I have to `cd` into the application current path before running the `rvm` commands? – Anjan Jul 11 '13 at 05:43
  • You do nor have to `cd` because `rvm-capistrano` is controlling your environment not the remote RVM, you need to create separate wrapper per application because `sudo` removes all the environment context set previously by `rvm-capistrano` and the wrappers restore proper environment settings so all ruby is set up correctly, there are other ways to do it - I just made it working from your start code. – mpapis Jul 11 '13 at 07:26
  • If it isn't too much trouble, could you also tell me what other ways there are? Also, is bluepill only available as a gem? If possible, wouldn't it be just better to install bluepill through the OS package manager, so it is available system-wide? – Anjan Jul 11 '13 at 09:34
  • from what I read https://github.com/arya/bluepill - you need separate gemset just for bluepill - and use aliased wrappers inside to start / stop application – mpapis Jul 11 '13 at 11:45