0

I have this task in may deploy.rb file:

desc 'open ssh session in background'
  task :ssh_in_background do

    run_locally do 
      execute "ssh -o 'ExitOnForwardFailure yes' -NMS ~/.ssh-tunnel -f #{fetch(:rails_env)}-#{fetch(:application)}"
      execute "exit" 
    end
  end

When I run this task, all it does is hang. It never quits despite the -f parameter.

How do I make this task exit so that capistrano will continue on?

Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • Did you find a solution to this yet? I'm trying something similar, running rails console thru an SSH tunnel. My code looks something like: `task :console => [:"deploy:set_rails_env"] do host = roles(:app).first run_locally do execute "ssh #{host.user}@#{host} -i #{host.netssh_options[:keys].first} -t 'cd #{current_path} && bundle exec rails #{task} #{fetch(:rails_env)}'" end end` but it keeps timing out after about 40 seconds and outputting "Pseudo-terminal will not be allocated because stdin is not a terminal." This used to work with cap 2.15.4, but I recently upgraded to cap3 – Isaac Betesh Feb 05 '14 at 22:31
  • @IsaacBetesh I switched from capistrano's `execute` to ruby's `system` command. – Eric Francis Feb 05 '14 at 22:40
  • Thanks. That didn't work for me; I also had to remove `run_locally`. See my comment on your answer below. – Isaac Betesh Feb 06 '14 at 00:46

1 Answers1

0

I switched from capistrano's execute to ruby's system command.

desc 'open ssh session in background'
  task :ssh_in_background do

    run_locally do 
      system "ssh -o 'ExitOnForwardFailure yes' -NMS ~/.ssh-tunnel -f #{fetch(:rails_env)}-#{fetch(:application)}"
    end
  end
Eric Francis
  • 23,039
  • 31
  • 88
  • 122
  • I couldn't get it working like this. Maybe something's different in my case because I'm using `ssh -t`, whereas you're using `ssh -f`. In any event, my solution was just to remove `run_locally`. My task now looks like this: `task :console => [:"deploy:set_rails_env"] do host = roles(:app).first system "ssh #{host.user}@#{host} -i #{host.netssh_options[:keys].first} -t 'cd #{current_path} && bundle exec rails console #{fetch(:rails_env)}'" end` – Isaac Betesh Feb 06 '14 at 00:45