autostop.sh does not work

  • Dear Forum,

    I have a - propably for most of you ridicolous question:

    I have a simple script in my /storage/.config/autostart.sh that triggers an IR LED to switch my beamer on:

    Bash
    #!/bin/bash
    sleep 10
    ir-ctl -S necx:0x3002
    )&

    this works like a charm :)

    Now I have setup the /storage/.config/autostop.sh to switch the beamer off in case of kodi shutdown (for this the IR signal has to be sent twice)

    Bash
    #!/bin/bash
    (
    sleep 5
    ir-ctl -S necx:0x3002
    sleep 1
    ir-ctl -S necx:0x3002
    )&

    For some reason (cannot find the logs, propably do not have them active) this doesn't work.

    I tried it with/without the sleep 5 at start.. same result

    For the autostop.sh i did the following:

    - created the file

    - made it executable chmod +x autostop.sh

    - gave it the same user rights as the autostart.sh

    Code
    -rwxr-xr-x    1 root     root           394 Apr  6 18:25 autostart.sh
    -rwxr-xr-x    1 root     root            78 Apr  8 19:35 autostop.sh

    What am I doing wrong or did I forget anything?

    Thanks a lot in advance!

    Hogo

  • Go to Best Answer
  • Don't run any commands in the background in autostop.sh. Remove ( and )& from your script.

    Background execution is used in autostart.sh to not delay the boot process. If used in shut down they are killed after a short time.

    For logging enable "Persistent Logging" in the "System" tab of the LE Settings Addon. After reboot use journalctl -b -1 -u kodi-autostart.

  • Background execution is used in autostart.sh to not delay the boot process. If used in shut down they are killed after a short time.

    Why are background jobs killed?

    Is this behavior a design decision or is there a fundamental technical reason for it?

    In other words, is there any way to work around this limitation by fiddling around with the systemctrl configuration?

    Normally, child processes should not be killed while the parent job is still active.

    I wrote a script to backup the Kodi databases and now painfully realized that the three parallel background jobs only produce corrupt tar.bz2 balls.

  • grv0815 That is how ExecStop of a systemd unit is working. After the main process did exit all remaining processes are killed.

    Edit: if putting the wait command at end of the script it will wait for all active background processes.

  • Thanks for your quick reply, mglae!

    I already use wait -n in my shellscript to limit the background jobs to a constant number. On the command line this works as expected.

    But if the script is started via autostart.sh, all started background processes are terminated prematurely - as described by you in #3.

    The observed behavior does not correspond to the (standard?) behavior of ExecStop, as described by you above in #6.

  • Use journal to check for errors/logs: journalctl or journalctl -u kodi-autostart.

    Please open an own thread with more information if the autostart issue persist.

  • Thanks mglae,

    the tip with the (persistent) journal helped me!

    In short: The sub processes work as expected and are terminated only after the end of the parent process, so a new thread is not necessary.

    This was masked by a astounding bug in the ntfs driver which destroyed the search structure of the directory entries. As a result, existing entries were not found and the rolling of the backup files failed.

    (Windows-)Chkdsk said about this:

    Code
    3 corruption records are checked....
    Record 1 of 3: Damage in index "$I30" of directory "\backup\dbdumps <0x4,0x198c2>" ... Corruption was found and fixed.
    Record 2 of 3: Index "$I30" of directory "\backup\dbdumps <0x4,0x198c2>" is sorted incorrectly ... The down pointer of the current index entry with length 0x18 is invalid.

    But this is another story and not your site.

    Thanks for the quick response and for this project!