Run docker container on boot but only after Kodi has loaded

  • Hi ,

    I"m able to successfully run a docker container and some scripts upon boot up via the use to But some of my scripts need Kodi to be up and running. Adding sleep in does not help as it delays the loading of Kodi as well.

    Since I am troubleshooting some other issues with the scripts and need to restart it manually as well (without system reboot) - I cannot add sleep because then

    upon manual restart the sleep will slow me down while testing and troubleshooting.

    Is there a way to run a script in Librelec upon boot but after Kodi has loaded ?

  • I created a service under /storage/.config/system.d/myServer.service with contents:

    1. [Unit]
    2. Description=Script to autostart my Services after kodi has loaded
    3. [Service]
    4. After=kodi.service
    5. ExecStart=/storage/.customScriptOnBoot
    6. [Install]

    But this fails to run. I get the following error message in journalctl "

    myServer.service: Failed at step EXEC spawning /storage/.customScriptOnBoot: Exec format error

    I don't see where the problem is with the format. Please advice. Thanks in advance.

  • Thanks vpeter .

    This resolved the Format error message but there still are two issues:

    1. The script does not get executed automatically upon boot after kodi loads.

    2. When I start it manually 'systemctl start myServer.service' it fails with error message "docker: not found."

    It looks like that the shell I enter into is not able to access the docker, because when I execute the docker command from command line in LE ssh I am able to get the desired results - docker loads and everything works.

    I even tried this:
    ExecStart=/bin/sh -c "/storage/.customScriptOnBoot"

    and still get the same error "docker: not found".

    Any other way to execute the script without opening up another shell? Thanks in advance.

  • Code
    1. ExecStart=/bin/sh -l /storage/.customScriptOnBoot

    Edited once, last by mglae: simplified using "-l" ().

  • Thanks mglae .

    This worked. My script is is able to find docker and execute it.

    The only problem remaining is the timing. The script executes before docker daemon and Kodi has completed loading. Any suggestions on how to delay the execution of this service until kodi has completed loading completely? I have the following set in script but it doesn't seem to work.

    1. After=kodi.service
  • Systemd only knows when Kodi is started and has no information about the internal state.

    You can create a systemd timer with OnBootSec= that start your service after a short time at boot.

  • Thanks mglae .

    That would have worked well and been an acceptable solution. In my situation the problem is that this embedded device does not have a RTC which means it was starting with incorrect time and correcting the time during boot up via NTP. I think that is preventing the OnBootSec= from working as desired.

    I removed everything and added the After=docker.service and that seems to have worked. It seems to kick off my script after Kodi loads even though I see docker starting up before kodi completes loading.

    I'll keep a close eye on it and will revert if this starts to fail. But for now, I think anyone wanting to run custom scripts that deal with docker and need kodi running before it could use the same settings

    1. [Unit]
    2. Description=Script to autostart Privatebox App after kodi has loaded
    3. After=docker.service
    4. [Service]
    5. ExecStart=/storage/.customScriptOnBoot
    6. [Install]

    Thanks for your help!

  • Another alternative would be to install portainer via the repo (their repo installer is in our repo) as this is wrapped as a Kodi addon and so depends on Kodi; so it won't be started until after Kodi starts, and any containers that it manages are started after portainer.

  • The Kodi addon packages are only used to install docker and portainer. They are started before Kodi as systemd services wanted by .

  • Another option would be to not define any restart options for the container and use a systemd service to manage it

  • I have similiar issue, but I need to run container BEFORE kodi tries to start.

    I installed MariaDB through docker

    1. docker run -d p 3306:3306 --volume=/storage/mysql:/config -e TZ="CET-1CEST,M3.5.0,M10.5.0/3" -e MYSQL_ROOT_PASSWORD=xoxo -e=MYSQL_USER=xyxy -e=MYSQL_PASSWORD=xzxz --name mysql lsioarmhf/mariadb

    Docker service is already in system.d. If I would define "--restart unless-stopped" for container, it would be started automatically, but I dont know how to control startp sequence. And I need to have DB up before Kodi start, obviously, to be able interconnect Kodi and MariaDB.

    I already tried /storage/.config/system.d

    where is just docker start mysql but for some reason this service doesnt work...

    2x VIM3L, 3x X96 Air P3, 6x C2; 6x RPi2; 3x Win7 Kodi + vPeter's mariaDB plugin as Library DB

    Edited 3 times, last by JimmySmith ().

  • Use the mariadb addon instead

  • Strange I cant make it work otherwise..

    I tried the plugin, its kinda works, but I cant disable binary logging there (propably because

    1. [email protected]:/# cat /etc/mysql/my.cnf | grep log_bin
    2. log_bin = /config/log/mysql/mariadb-bin
    3. log_bin_index = /config/log/mysql/mariadb-bin.index

    is defined within container, and its not possible to disable binary logging through custom.cnf)

    and I dont know why, but mysql is toooo slow. Dunno, if its by docker, or MariaDB, or kodi version (leia), but Kodi 16.1 with vPeters MySQL is really snappy compared with [email protected]+mariadb :(

    2x VIM3L, 3x X96 Air P3, 6x C2; 6x RPi2; 3x Win7 Kodi + vPeter's mariaDB plugin as Library DB