I''m working on a sweet little module to manage ssh tunnels using
Net::SSH and daemons. Before I try to add a service provider in order
to manage daemons, I figured I''d just exec and am running into a very
strange situation.
First, here is a simple proof of concept involving 3 small files:
(Please forgive the overly simplified and abstract examples.. just
trying to keep this as short as possible)
#/tmp/foo.rb:
loop do
sleep 5
end
#eof
#/tmp/foo_control.rb:
require ''rubygems'' unless defined?(Gem)
require ''daemons''
Daemon.run(''/tmp/foo.rb'')
#eof
Manual runs of ruby /tmp/foo_control.rb start/stop/restart results in
the expected behavior, the (useless) daemon is managable and well
behaved :)
Taking this a bit further, I can involve Puppet like so:
#foo.pp
exec { test_it
command => "ruby /tmp/foo_control.rb start",
creates => ''/tmp/foo.rb.pid'',
user => ''akosmin'',
}
and then I can start the daemon with a simple
sudo puppet apply foo.pp
OK, everything seems great at this point but if I replace foo.rb''s
useless sleep with the following ssh tunnel, the daemon appears to
start but then exits but only when exec''d from Puppet. Here''s
the
updated /tmp/foo.rb:
require ''rubygems''
require ''net/ssh''
Net::SSH.start(''box1.example.com, ENV[''LOGNAME'']) do
|ssh|
ssh.forward.local(7777, box2.example.com, 22)
ssh.loop { true }
end
Running this manually (ruby /tmp/foo_control.rb start) from a shell
spawns the daemon, no problem. I can start it, query the status, or
stop it. I''m pointing this out in order to spare anyone from wondering
if the ssh bits are working. The problem comes when I simply exec it
via Puppet (see above). It seems like the daemon starts but then after
a second, it dies. Again, I can run the exact command the exec type is
using and everything works as expected. I''ve added --debug and --trace
and have no additional information to report as the output just tells
me everything is working as expected.
Does anyone have any ideas?
Best,
Adam
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
windowsrefund
2011-Nov-27 23:28 UTC
[Puppet Users] Re: My ssh tunnels get no love from exec
No fix yet but I see a small typo in my original post.> Daemon.run(''/tmp/foo.rb'')should be Daemons.run(''/tmp/foo.rb'') -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
windowsrefund
2011-Nov-28 01:24 UTC
[Puppet Users] Re: My ssh tunnels get no love from exec
For reasons that are clearly beyond me, it''s now clear that /tmp/ foo.rb is being run as root despite the controller script running as ''akosmin''. I don''t get it :/ -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
windowsrefund
2011-Nov-28 15:49 UTC
[Puppet Users] Re: My ssh tunnels get no love from exec
Looks like this is related to rvm and the fact that the user''s environment is not sourced when puppet changes user context. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.