SH script in autostart.sh did not work

  • Hi,

    I am using libreelec 9.2.1 and want to start TVmosaic automatically on startup. So I created autostart.sh with the following lines:


    #!/bin/sh

    (

    sh /storage/tvmosaic/start2.sh

    ) &


    If I run the autostart.sh manually it is working but when I reboot the Pi the start2.sh script will not executed. Generally the autostart.sh will be executed.

    I tested it on creating a text file with autostart.


    Has anybody an idea why the script will not execute on reboot?

  • Thanks chewitt for your replay.

    I tried this but it did not work, too.

    When I execute the autostart.sh manually (by hand) then it works.

    At the startup it doesn't work.

  • Some scripts assume you're already at their folder. So try:

    Code
    1. cd /storage/tvmosaic
    2. /usr/bin/sh start2.sh

    Or make autostart.sh a link to start2.sh by using ln -s.

    Flexin' vinyl, jammin' break beats. 8)

  • Thanks for testing. Remove the (...) &, which makes the call a background process. Make sure both scripts have executable permissions (chmod +x).

    Flexin' vinyl, jammin' break beats. 8)

  • My autostart.sh scrpt has only the both commans:


    1. cd /storage/tvmosaic
    2. /usr/bin/sh start2.sh

    Both scripts have execute permission.


    => Again no luck.

  • Then post the start2.sh script please. When it's a large script, use a link to Pastebin for publishing.


    Start another simple shell script (test file creation etc.) from autostart.sh to be sure that shell-script-to-shell-script works.

    Flexin' vinyl, jammin' break beats. 8)

  • Here is the start2.sh script:


    #!/bin/sh


    . $(dirname $0)/incl


    export LD_LIBRARY_PATH=${TVM_ROOT_DIR}/lib

    export TVMOSAIC_ROOT_CONFIG_DIR=${TVM_ROOT_DIR}


    ${TVM_ROOT_DIR}/tvmosaic_server

    1. remove the second line . $(dirname $0)/incl
    2. replace the third line by export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TVM_ROOT_DIR}/lib
    3. find the value of variable TVM_ROOT_DIR by: echo $TVM_ROOT_DIR
    4. create the line export TVM_ROOT_DIR=/YOUR_TVM_ROOT_DIR

    Result should be like (/YOUR_TVM_ROOT_DIR replaced by the result you found at point 3):

    Shell-Script
    1. #!/bin/sh
    2. export TVM_ROOT_DIR=/YOUR_TVM_ROOT_DIR
    3. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TVM_ROOT_DIR}/lib
    4. export TVMOSAIC_ROOT_CONFIG_DIR=${TVM_ROOT_DIR}
    5. ${TVM_ROOT_DIR}/tvmosaic_server

    Flexin' vinyl, jammin' break beats. 8)

    Edited once, last by Da Flex ().

  • Now I tried this:


    #!/bin/sh


    export TVM_ROOT_DIR=/storage/tvmosaic

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TVM_ROOT_DIR}/lib

    export TVMOSAIC_ROOT_CONFIG_DIR=${TVM_ROOT_DIR}

    ${TVM_ROOT_DIR}/tvmosaic_server


    but it only works manually. Not at reboot.


    I recognized an error message at booting:


    Failed to start Apply Kernel Variables


    Maybe this depends on my problem?

  • Theory: /etc/profile initializes environment variables for add-on's, but will only get executed when starting a shell session.

    To include this process into your script, try:

    Shell-Script
    1. #!/bin/sh
    2. . /etc/profile
    3. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${TVM_ROOT_DIR}/lib
    4. export TVMOSAIC_ROOT_CONFIG_DIR=${TVM_ROOT_DIR}
    5. ${TVM_ROOT_DIR}/tvmosaic_server

    Flexin' vinyl, jammin' break beats. 8)

  • Theory 2: Your add-on starts a server application, which needs some time to come up.

    So try this autostart.sh:

    Shell-Script
    1. #!/bin/sh
    2. (
    3. sleep 3
    4. /usr/bin/sh /storage/tvmosaic/start2.sh
    5. ) &

    If this works, you can play around with sleep time (sleep 2 for two seconds, sleep 1 for a second).

    Flexin' vinyl, jammin' break beats. 8)

    Edited once, last by Da Flex ().

  • If you need to control start sequencing use a system.d service, you have a lot more control over when things happen.