Delay the start of PM4K Add-On until VPN is active

  • Hi

    Just signed up; not sure if this section is the right place for my question. If not, pls indulge me ;)

    Found this:

    HiassofT
    November 26, 2019 at 11:42 PM

    I am trying to do the something similar, but with this Add-On:

    PM4K for Plex | Omega | Addons
    PlexMod for Kodi
    kodi.tv


    So, the add-on has a setting for it to start automatically once Kodi starts, BUT even though the network is available by then, the VPN is not. Starting the add-on without VPN tunnel active means that it cannot access the PLEX library. It does not periodically scan for the librabry, so if said librabry cannot be accessed upon start of the add-on, I am screwed. What I am after is a few lines of code that will make the add-on wait for the VPN tunnel to be up and then, and only then, to start.

    Anyone?

  • What I am after is a few lines of code that will make the add-on wait for the VPN tunnel to be up.

    You cannot delay the add-on inside Kodi, but you can use a systemd service to schedule the VPN to start after the network is up and before Kodi, so the tunnel is established before Kodi autostarts the PM4K addon.

    Have a look at /storage/.config/system.d/wireguard.service.sample and tweak that to suit whatever VPN technology you're using, e.g. if using OpenVPN not WireGuard, substitue an openvpn command instead of the connmanctl connect command. NB: If using OpenVPN you should really investigate using WireGuard instead as it'll significantly increase tunnel throughput on the same point-to-point connection.

  • Oh boy

    Well, there already was a service for OpenVPN in system.d.

    I compared to connman and the only difference I reckon is relevant in this context was the [Installation] part.

    There, I put

    Code
    WantedBy = multiuser.target

    replacing the line that was in there

    Code
    WantedBy = kodi.target

    This however doesnt guarantee success. When connected via LAN, it seems to be connecting quickly enough. As soon as I let the Pi connect via hotspot outside of the local network, the add-on still starts bevore VPN has been established.


    Sorry, probably I am doing this wrong not knowing anything about code.

  • See how that ^ works?

  • Good morning

    Thank you for your efforts!

    The splash screen that is displayed during launch of the PM4K add-on now stays a bit longer.

    It gives the appearance of it only moving forward once the OpenVPN connection is established (as is evident by the top-right corner notification from Kodi/zomboided manager.

    However, this still then goes into the landing page of PM4K not showing any media found.

    I have tested this with a wifi connection of the Pi to my phone as a hotspot (hence outside local network) and also with my local wifi. The latter connects faster, but still gives the same result.


    I imagine, a wait command after VPN has been established successfully might do the trick?

  • No harm in trying .. ^

  • Will not help, nobody is waiting for the service.

    You can add before=multiuser.target but then boot is delayed until time-sync.target is reached and you stuck in splash screen without internet connection.

    Better develop some kind of vpn-online.service using a time out and add it to the chain. Remove time-sync.target from the dependencies and rely on a larger timeout of network-online.target set in LibreELEC-Settings addon.

  • sh33p0mat, Have you set VPN to start in libreelec before kodi using the VPN manager monitor tab.

    Connect VPN before Kodi starts (LibreELEC only)

    Modifies the start up procedure of LibreELEC to start the VPN connection at the same time as Kodi. Requires that at least one connection has been validated.

    Be aware that if your openvpn connection takes a long time to connect then it maybe that Kodi starts up before the openvpn connection has been established. I don't see this on a wired network using PIA but your experience maybe different.

    Once Kodi and subsequently the add-on has been started, if an openvpn task is found to be running a notification will be displayed to inform the user a VPN connection is running. If no task is found, and there is no VPN connection then a further attempt to connect will be tried (with the usual set of notifications or connecting and success or failure).

  • Hi

    Tried the revised code of chewitt - no change

    Read the input by mglae - frankly, I do not undertand it ;)

    Grasshopper yes, I did try that before even launching this thread. That does not solve the issue either. Still the add-on P4MK within Kodi seems to be starting so quickly, that the VPN is not fully up at that time yet.