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

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

<service
    name="network/ssh-tunnel"
    type="service"
    version="1">

    <create_default_instance enabled="false"/>

    <single_instance />

    <dependency
       name='nameservice'
       type='service'
       grouping='require_all'
       restart_on='none'>
         <service_fmri value='svc:/milestone/name-services' />
    </dependency>

    <exec_method
          type='method'
          name='start'
          exec='/usr/bin/ssh -fNx -L 3307:127.0.0.1:3306 mysql1'
          timeout_seconds='0'>
    </exec_method>

    <exec_method
           type='method'
           name='stop'
           exec=':kill'
           timeout_seconds='0'>
    </exec_method>
</service>
</service_bundle>
share|improve this question
    
I use autossh to control network errors –  adnako Mar 4 at 9:19

1 Answer 1

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:127.0.0.1:3306 mysql1'

hth,

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

 
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.