OPNsense Forum

Archive => 18.7 Legacy Series => Topic started by: ktk on November 10, 2018, 09:34:11 am

Title: [SOLVED] Autostart a script after WAN connection is up
Post by: ktk on November 10, 2018, 09:34:11 am
I have a machine in a mobile carrier network with a private IP as WAN address. To be able to remotely connect to the machine I use autossh, which seems to work fine. I've created the following /usr/local/etc/rc.autossh script:

#!/bin/sh
autossh -M 19984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /root/.ssh/id_rsa -R 24385:localhost:22 remote-ip.somewhere.org -l remoteuser &


For starting it I did:

cat /etc/rc.conf.d/autossh
autossh_enable="YES"


When I reboot the box, this script does not seem to be up. Did I miss something or might this be because there is no default gw yet at the stage where it gets triggered?

If so, is there any way I can let the script get executed once I have a WAN IP & GW?
Title: Re: Autostart a script after WAN connection is up
Post by: franco on November 10, 2018, 09:46:13 am
autossh_enable="YES" should do the trick if it's the correct rc.conf variable.

Otherwise call you script via rc.syshook "start": https://docs.opnsense.org/development/backend/autorun.html

I think there is an autossh plugin coming soon.


Cheers,
Franco
Title: Re: Autostart a script after WAN connection is up
Post by: ktk on November 10, 2018, 10:41:59 am
thanks, I just assumed it's the variable I would have to take, or are they "registered" somewhere? My guess was it has to be named like the rc-script I created.

"start" looks great, will check that out thanks
Title: Re: [SOLVED] Autostart a script after WAN connection is up
Post by: ktk on November 10, 2018, 11:00:01 am
The "start" script works great, thanks @franco!
Title: Re: [SOLVED] Autostart a script after WAN connection is up
Post by: franco on November 10, 2018, 11:22:55 am
Yay, cool. I double-checked the FreeBSD port:

It does not ship an rc.d script so autossh_enable="YES" is never read and acted upon.


Cheers,
Franco