Kodi Community Forum

Full Version: Start Script (.sh/VPN) before XBMC?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Guys,

i have to ask for your help again. Smile

My Mission:

I want to use shared libraries via MySQL with my Pi (OpenElec 13.0 Alpha) and my Win8 Client, both are connected to my external server via VPN. The problem is, before my pi has access to my mysql database, it has to be connected to my VPN.

Are there any ways to start my VPN-script (.sh) before XBMC boots up?

Thank you in advance!

best regards
In OpenELEC, look at adding an autostart.sh script - it runs before XBMC is started so you can bring up the VPN before XBMC.
Hi Milhouse,

really thanks for your fast reply, its perfect cuz im using your build anyway Smile

Ive created an autostart.sh with the following content:

#!/bin/sh
openvpn /storage/.config/raspi.ovpn

If i start the pi now, he connects but didnt start xbmc.
The screen stays black after first boot parameters, but i can see the incoming vpn connection on my server, so the script works.

Does xbmc maybe wait for an reply from the script, that it is finished, or do i have to tell em separately, that he have to start xbmc now?
(2013-12-19, 17:17)robby1337 Wrote: [ -> ]Does xbmc maybe wait for an reply from the script, that it is finished, or do i have to tell em separately, that he have to start xbmc now?

You need to fork the openvpn process so that it is started as a separate process, then exit from autostart.sh when you are sure your VPN is up.

Something like:
Code:
#!/bin/sh
openvpn /storage/.config/raspi.ovpn &
sleep 5

Adjust the "sleep 5" line to allow sufficient time for the VPN to be brought up. Or replace the "sleep 5" line with a while loop that tests for a "VPN up" condition every 0.25 second, so that you wait only as long as necessary for the VPN - this is how I wait for the network on my Pi:
Code:
# Wait for the network to come up...
while [ -z "$(connmanctl state 2>/dev/null | grep State | grep -E "ready|online")" ]; do sleep 0.25; done; logger -t "$(basename $0)" "** Network is up **"

You just need to change the "while" condition to suit your VPN.
Code:
Code:
#!/bin/sh
openvpn /storage/.config/raspi.ovpn &
sleep 5

That worked perfectly!

I chose 8 secs, just to be sure (idc bout 3 secs more or less, didnt restart Pi that often)

MySQL sync up and running!

Thanks again, youre my hero! Smile