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'

  • 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'


  • 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. – Harry Love May 12 '11 at 18:38
  • Adding sleep() after ssh doesn't work because ssh will return a failure first before sleep is called. – Harry Love 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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