Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

Nesting and authenticating resque-web on ey-cloud

Mike Barinek
Monday, September 13, 2010

Wouldn’t it be nice to include the resque-web interface underneath your current application’s url?

Wouldn’t it then be nice to use the same authentication mechanism that your web application uses?

Here’s a solution that we used on a recent Rails 2.3 ey-cloud project that accomplished both goals.

First, we created a simple resque_web.ru file within our Rails 2.3 project. In this example we used the same Warden SSO authentication mechanism and fired up the resque-web server from the new mapping.


# Set up Resque environment
resque_config = YAML.load_file(File.join(File.dirname(__FILE__), 'config', 'resque.yml'))

env = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development'
Resque.redis = resque_config[env]

map '/resque-web' do
  use Rack::Session::Cookie, :key => 'rack.session',
    :path => '/',
    :expire_after => 60 ** 2,
    :secret => 'supersecretresquekey'

  use CasrackTheAuthenticator::Simple, :cas_server => "http://sso.your_sso_server.com"
  use CasrackTheAuthenticator::RequireCAS
  use Rack::ShowExceptions
  run Resque::Server.new
end

The important piece here is that we use ‘/resque-web’, we’ll use this same path in a bit within our Nginx configuration. We also used the rack session cookies with our SSO authenticator.

Another interesting piece here is that we’re using Castronaut and Casrack the Authenticator, which makes SSO pretty straight forward.

Next we created an upstream server in Nginx to resolve the path. We’re just using Thin here.

Here’s our Chef template for the upstream server.


upstream resque_web_upstream {
   server unix:/var/run/engineyard/<%= @app_name %>/<%= @app_name %>.thin.1.sock;
}

The important piece here is that the upstream server lives outside of our web application config area.

Here’s our Chef recipe for creating the upstream server file.


template "/etc/nginx/servers/resque_web.conf" do
  owner "root"
  group "root"
  mode 0755
  source "resque_web.conf.erb"
  variables({
    :app_name => app_name
  })
end

And then finally, we created a new custom location within our Nginx server configuration.

Here’s our Chef template for the custom Nginx Location.


location /resque-web {
  proxy_set_header Host $http_host;
  include /etc/nginx/common/proxy.conf;
  proxy_pass http://resque_web_upstream;
}

And here’s our Chef recipe for creating the custom location file.


template "/etc/nginx/servers/#{app_name}/custom.locations.conf" do
  owner "root"
  group "root"
  mode 0755
  source "custom.locations.conf.erb"
  variables({
    :app_name => app_name
  })
end

That’s it!

  • 0 Shares
  • Share on Facebook
  • Share on Twitter

One comment

  1. Rob Olson says:

    Nice! I was wondering how this might be done with Rails 2.3.

    This is really slick with Rails3 + Devise as well: http://blog.kiskolabs.com/post/776939029/rails3-resque-devise

    September 16, 2010 at 10:53 pm

Add New Comment Cancel reply

Your email address will not be published.

Mike Barinek

Mike Barinek
Boulder

Recent Posts

  • American Thrombosis and Hemostasis Network (ATHN) is looking for a Web Application Developer
  • Portico is looking for a Web Application Developer
  • Testing Ruby Services without Mocks
Subscribe to Mike's Feed

Author Topics

boulder (4)
jobs (3)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >