Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm tunneling from our web server to our MySQL server, both on Solaris boxes. I've created a SMF manifest for the ssh tunnel in order to reconnect when the web server box reboots. This works great.

The problem is I'm not sure what to do when the MySQL box reboots. This external closure of the tunnel is passed to SMF, which tries to restart the tunnel in rapid-fire succession 3 times before putting the service into maintenance mode. Is there a way to specify a "retry-every" or something similar? Is there another way I should approach the problem?

Here's the SMF I'm using.

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">

<service_bundle type='manifest' name='ssh-tunnel'>


    <create_default_instance enabled="false"/>

    <single_instance />

         <service_fmri value='svc:/milestone/name-services' />

          exec='/usr/bin/ssh -fNx -L 3307: mysql1'

share|improve this question
I use autossh to control network errors – adnako Mar 4 '14 at 9:19

You can specify how long to wait between executions of the exec command in the 'exec_method' sections in the timeout_seconds variable. If you set it to 60 it would try immediately wait 1 minute then try again and the wait & try. The value you would set depends on how the MySQL box takes to boot.

Another way you could do it is to specify a sleep command as part of the exec, for example to wait 1 minute before before running the ssh :

exec='sleep 60 && /usr/bin/ssh -fNx -L 3307: mysql1'


share|improve this answer
Timeout_seconds is the number of seconds to wait before killing the process, not the duration to wait before retrying. timeout_seconds=0 means an unbounded limit, i.e., wait forever before killing the process. Unfortunately, ssh returns a failure immediately if it cannot connect, which is why SMF tries to connect again immediately. Adding sleep() to the process is not an option before running ssh because I need it to connect immediately if the web server reboots. – harrylove May 12 '11 at 18:38
Adding sleep() after ssh doesn't work because ssh will return a failure first before sleep is called. – harrylove May 12 '11 at 18:50
Could you put your tunnel cmd into a script which doesn't exit on ssh failure and used that script in the exec_method? – Martin May 13 '11 at 8:00

Your Answer


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.