OpenWrt Forum Archive

Topic: Cannot start multiple instance of autossh

The content of this topic has been archived on 16 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

problem seen on lanturtle which uses openwrt as base system.

/etc/init.d/autossh can't start multiple instance of openssh.
service_start uses start-stop-daemon w/ -x /path/to/openssh,
since SERVICE_NAME_MATCH and SERVICE_PID_FILE aren't defined,
once the first instance of openssh is started, the next ones
aren't launched bcoz start-stop-daemon already see the first
instance.

it is possible to launch more than one openssh session using
the following changes...

in function start_instance of /etc/init.d/autossh (autossh.init)

before :
        export AUTOSSH_GATETIME="${gatetime:-30}"
        export AUTOSSH_POLL="${poll:-600}"
        service_start /usr/sbin/autossh -M ${monitorport:-20000} -f ${ssh}

after :
        export AUTOSSH_GATETIME="${gatetime:-30}"
        export AUTOSSH_POLL="${poll:-600}"
        export AUTOSSH_PIDFILE="/var/run/autossh.${ssh##* }.pid"
        export AUTOSSH_LOGFILE="/var/log/autossh.${ssh##* }.log"
        SERVICE_PID_FILE="${AUTOSSH_PIDFILE}"
        service_start /usr/sbin/autossh -M ${monitorport:-20000} -f ${ssh}

${ssh##* } is used to get the user@host or host target.

this permit to have something like :

root@turtle:~# cat /etc/config/autossh

config autossh
        option gatetime '0'
        option monitorport '30022'
        option poll '600'
        option ssh '-i /root/.ssh/id_rsa -N -T -R 32200:localhost:22 host1'

config autossh
        option gatetime '0'
        option monitorport '40022'
        option poll '600'
        option ssh '-i /root/.ssh/id_rsa -N -T -R 42200:localhost:22 host2'

Regards

PS : can't register/submit a trac defect => Submission rejected as potential spam !

I tried this too, to put multple configurations in /etc/config/autossh, but I did not manage.

I put them now in /etc/rc.local which works fine. The autossh mechanism makes that it makes no difference how you start it.

I read somewhere (but where?) that it should be possible to create multiple /etc/init.d/autossh"x" (with discriminant names, of course) each referring to its own  /etc/config/autossh"x".

A third option would be to tweak the source code (http://www.harding.motd.ca/autossh/) (not recommended) or modify /etc/init.d/autossh, so that is parses /etc/config/autossh and detects multiple configurations and starts multiple instances. The most elegant solution, I think.

The beauty of open source!!!

(Last edited by maartenjd on 23 Nov 2016, 11:43)

The discussion might have continued from here.