Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background hangs when ran in within blocks #73

Closed
mumoshu opened this issue Dec 11, 2013 · 3 comments
Closed

background hangs when ran in within blocks #73

mumoshu opened this issue Dec 11, 2013 · 3 comments

Comments

@mumoshu
Copy link

mumoshu commented Dec 11, 2013

Hi,

Thanks a lot for the great software!
I'm getting more and more excited as I see how flexible SSHKit (and of course Capistrano 3) is :)

I have found that background hangs when used within within blocks.
I'm running Capistrano 3.0.1 with SSHKit on Ubuntu 12.04.

With the code below, run cap test will_hang1 to reproduce the hangs. You can also run cap test wont_hang to see how to fix those.

As far as I know, the problem here is that nohup seems to hang when executed after cd.
We can probably avoid the hangs by changing background to emit shell commands like cd the_dir; ( ( nohup the_command &>/dev/null ) & ).

I suspect that the issue is arrising from Net::SSH(ref). So I believe that we can do a work-around on SSHKit side or just document it in Usage Examples.

# config/deploy/test.rb

task :will_hang1 do
  on roles(:local) do
    within '/home/vagrant' do
      background 'nc -l 12345'
    end
  end
end

# FYI, Don't do the below, too!
task :will_hang2 do
  on roles(:local) do
    execute "( ( cd /home/vagrant; nohup nc -l 12345 &>/dev/null ) & )"
  end
end

task :wont_hang do
  on roles(:local) do
    execute "cd /home/vagrant; ( ( nohup nc -l 12345 &>/dev/null ) & )"
  end
end

Regards,
Yusuke

@leehambley
Copy link
Member

Hi Yusuke, thanks for the feedback.

Do you think it'd be possible to change the composition of the stringer method to fix this with the first format? I admit to not having tried the background() method in the wild, I assumed that syntax would be correct!

I think for most cases, the 3rd example you posted is correct. In Capistrano the composition of things using the DSL is quite convenient for the most cases, but in advanced cases composing your own command as a string is often easier (although then one sacrifices access to the command map, which is a feature which mostly exists for Capistrano)

I would be fine with removing background() if it's clear that it doesn't work properly.

@stas
Copy link

stas commented Dec 17, 2013

Hi guys,
I'm also having troubles with background.

nohup: failed to run command `RBENV_ROOT=/home/deployer/.rbenv': No such file or directory

I guess the issue is caused by the wrong order of rbenv hooks or something.

@leehambley
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants