Need help around shutdown.sh

  • Hi,

    I read in LE-wiki that network already has shutdown when shutdown.sh runs.

    In other context I read, that dependency to network could be added by adding a line "Requires=network.target".

    I tried that with kodi-poweroff.service - but it does not make a difference.

    Can anybody tell me, how to get shutdown.sh run before network shutdown?

    Or if its not possible, could you explain the reason?

  • Looks like shutdown.sh is not executed at all.

    I added a touch [somefile] but that file does not appear.

    Same operation added to autostart creates the keyfile.

    I tried to enable kodi-halt.service and kodi-poweroff.service but that did not change anything.

    What am I missing?

  • Ok, its all about shutting down the nas.

    I use some nas for movie storage, which I turn on right before watching movies. When I'm finish watching movies I'd like to shutdown nas. Actually I use script-launcher addin for that purpose.

    The drawback is, that reason is ugly and its an additional step at shutdown process. I have to enable addin-category at media-main-menue and of cause my memory is far from reliable and so often I forget to execute the script and then have to poweroff the nas without shutting it down.

    I don't know whether just powering the box off could cause any harm ...

    In any case I don't like that praxis.

    Recently I read about shutdown-script in LE-wiki and thought, if I could change point of execution to before network shuts down, I could add the nas-shutdown to that script.

    That leaded to several tests. First I had to realize, that I can't change content of service-scripts.

    So I checked out LE-sources and started to build my own image.

    On that image I changed kodi-poweroff.service and kodi-halt.service and added a "requires=network-online.target" and enable both services by using systemctl enable ... - but I could not see any change. nas did not shutdown on shutting down kodi.

    So I added a "touch [somefile]" to shutdown.sh, but on next start the file has not been created - so I suspect, that shutdown.sh script is not going to be executed.

    I also thought about adding an entry to kodi-poweroff-menue. I found the patch-files that changes the menue-handling. Don't know, whether it would be possible, to add a menue entry.

    Best would be, to change current shutdown-process, so that I can't forget to shutdown nas.

  • Hi,

    recently i noticed that during shutdown some errors occur. When kodi disappears some red messages appear. However, the time until the display turns off is too short to read the messages.

    Have already installed rsyslog addon - unfortunately it changed nothing. No additional logfiles ...

    What else could I do to get rid of the shutdown errors or log the shutdown process permanently?

  • Just a few brief thoughts.

    Modifying systemd services

    Use /storage/.config/system.d to create systemd drop-in directories or your modified service files. Additional units can be created too.

    Persistent Logging

    Can be enabled via LE Settings Addon's System tab. Use journalctl -b -1 to view last boot. Logs are visible until local file systems are unmounted on shutdown.

    Final error messages

    Do exist because neither /flash/SYSTEM nor /flash can be cleanly unmounted while still being used.

    Shutdown scripts

    Due to target dependencies network access is not possible in shutdown.sh. Use autostop.sh

  • Thank you for your valuable thoughts!

    I started experiments with shutdown.sh script cause shutdown.sh receives script parameters to differ between shutdown and reboot. autostop.sh does not have such parameters, therefore its not what I want.

    Any idea, how I could determine in autostop.sh whether system is going to shutdown or is going to reboot?

    Would it be possible to create a key-file by using LE-patch system?

    In script I could then check existance or better content of key-file ... ?

  • Great! Thank you very much for the pointer!

    I adapted the idea to my needs, which leaded to this script:

    Bash
    #!/bin/sh
    poweroff=$(/usr/bin/systemctl list-jobs | egrep -c 'poweroff.target.*start')
    if [ ${poweroff} -gt 0 ]; then
       echo "power off system" > /storage/lastShutdown
       # code 4 NAS shutdown comes here
    else
       echo "rebooting system" > /storage/lastShutdown
    fi

    I love this solution! - I don't have to use self-compiled images and nas-handling works under the hood like desired.

    Perfect!