Search code examples
ruby-on-railscapistrano

capistrano-resque error with remote Redis DB


Hey I'm configuring my capistrano-resque, and I have a remote redis DB.

This is how my capistrano-resque configuration looks in deploy.rb:

set :resque_environment_task, true
role :resque_worker, ENV['REDIS_SERVER']
role :resque_scheduler, ENV['REDIS_SERVER']
set :workers, { "*" => 1 }

When I try to run cap production git:check, deploy:check I get the following error:

INFO [1df5c9be] Running /usr/bin/env mkdir -p /tmp/mk/ as deploy@ipaddress
INFO [b91cbf1f] Running /usr/bin/env mkdir -p /tmp/mk/ as redis@//x
DEBUG [1df5c9be] Command: /usr/bin/env mkdir -p /tmp/mk/
DEBUG [b91cbf1f] Command: /usr/bin/env mkdir -p /tmp/mk/
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as redis@//x: getaddrinfo: nodename nor servname provided, or not known

SocketError: getaddrinfo: nodename nor servname provided, or not known

It seems like there is something with redis@//x ? I have the full connection string stored as a local env both locally and in production:

redis://x:[password]@aws-eu-west.0.dblayer.com:10156 

Anybody have an idea on what's wrong?


Solution

  • The problem is that you're supplying a Redis address instead of an SSH address. Capistrano uses SSHKit to execute remote SSH commands on the server -- whatever you set as the role will be the server it uses. The role :resque_worker line isn't anything fancy we added in capistrano-resque, it's just assigning another role for Capistrano/SSHKit to use (in addition to the default app/web/db roles Capistrano includes by default).

    In other words, the :resque_worker setting isn't to specify which Redis server contains your job queue, it's to specify which server to run commands like rake resque:work on.

    So in a single-server scenario, your :resque_worker role should probably be the same as your role :app ... line, for example:

    role :app, "[email protected]"
    role :resque_worker, "[email protected]"
    

    Doing so would connect via SSH to to the me account at example.com and execute the commands.

    See http://capistranorb.com/documentation/getting-started/preparing-your-application/ (Section 4) for more info on how roles are defined/used.