Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have 3 shell scripts that each contains a while true loop and "calls" home to open a reverse ssh tunnel. The tunnels work.

I've Googled around, but not sure what will work for this. My main concern is that the loop in the script will block the boot instead and fire-and-forget.

I currently do not have physical access to the remote machine, so I can't play around to see if it works, I need something that will work, and keep working.

My hopes for this question is a step-by-step guide, since I am not very confident in messing with the things needed for this to work.

share|improve this question

1 Answer 1

It used to be the case that you could put a call to each of those scripts in a 'respawn' entry at the bottom of /etc/inittab, and be done with it. Simple. But ever since Debian switched to using upstart instead of init, and deprecated inittab, things have gotten more complicated and fragile. You'll need to write an upstart configuration file; those go in /etc/init, and they're easier to get wrong.

What you might do is grep through the contents of /etc/init/* looking for existing configs which use the 'respawn' keyword, and that start some network daemon -- these should already have dependencies stated that ensure the network is already up. Copy and modify one of those for each of your tunnels. The convention is to put your own configs in /etc/init/local/*. You might be able to remove some of the fragility by starting your tunnels earlier during boot, and just letting them hang, die, timeout, or whatever when the network isn't up yet. The 'respawn' will eventually respawn them, possibly after a longer timeout if they retried too many times earlier.

As long as you're using 'respawn', you're relatively safe from hanging the boot process - but with upstart, anything is possible; its increased flexibility means that configuration errors can hang boot in less-than-obvious ways; visual inspection is no longer as reliable as it was with inittab.

By the way, you probably don't need those 'while true' scripts. I usually use 'autossh' to start and manage these sorts of tunnels. It tends to be more reliable than a typical script, and the autossh command can be put directly in an /etc/init configuration file.

I hesitate to give you an example configuration file, because upstart configurations can be different enough that what works for me might not work for you (more of that fragility). But here is one of my autossh configs -- this might go in, say, /etc/init/local/autossh-example.conf. You'll note that I'm not explicitly stating any dependency on any network setup -- I'm expecting the 'respawn' to cause retries until the network is there. You'll want to test this locally on an identical machine before trusting it on your remote machine:

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /usr/bin/autossh -R 20042:127.0.0.1:22 -N foo.example.com
share|improve this answer
1  
+1 for autossh. –  EEAA Apr 28 '12 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.