开发者

webistrano ssh-agent

I have a Webistrano setup that deploys with its own private/public key pair. I would like to harness the simplicity of :remote_cache strategy, but don't want to copy the private key to the deployment server.

So long I have these tasks set up:

namespace :ssh do 
  task :start_agent do 
    ssh_options[:forward_agent] = true
    result = `ssh-agent -t 600`
    # Extract env variables
    %w(SSH_AUTH_SOCK SSH_AGENT_PID).each do |key|
      if result =~ /#{key}=(.*?);/
          ENV[key] = $1
      end
    end
    cmd = "ssh-add #{ssh_keys}"
    result = `cmd`
  end 

  task :stop_agent do
    # Kill the agent started previously
    `ssh_agent -k $SSH_AGENT_PID`
  end
end 

before 'deploy', 'ssh:start_agent'

This before :deploy seems to work half way, but I have few problems:

  1. I need to stop the agent after deploy (and after failed deploy). Is there any callback I can hook the ssh:stop_agent task?
  2. The deploy:update_code task fails with error Unable to resolve revision for 'master' on repository 'git@git.eenet.ee:base/mms.git'

Can an开发者_开发技巧ybody shed any light on this?


To answer my own question, I resorted to externally start ssh-agent via cron @reboot and bind it to a pre-known socket and add webistrano key to that agent:

@reboot laas sh -c 'eval `ssh-agent -a /path/to/my/ssh-agent.sock`; ssh-add /path/to/webistrano/config/id_rsa'

So that I can write a simple Webistrano recipe that configures ENV to use that socket:

ssh_options[:forward_agent] = true
ENV['SSH_AUTH_SOCK'] = '/path/to/my/ssh-agent.sock'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜