shutdown.sh is executed after network is down

  • Hello people,
    according to this thread (LibreELEC) David1977 recommended me to file this bug report in order to develop a fix for the following issue, in short words:

    The shutdown.sh is running after network is done, which lets LE freeze at shutdown when a script or a command in the shutdown.sh needs the network connection.

    So it is in my case in order to shut my NAS down at the same time LE powers off. Which is quite handy for me.

    So hopefully someone can find the issue, which is probably solveable when we can fix the point in the systemD thing which causes the problem.

    Ok so i hope i could make this clear and im looking forward to solve this.

    edit:
    The only thing i could find is that the problem already seemed to appeared some time ago (systemd does not wait for /storage/.config/shutdown.sh · Issue #3111 · OpenELEC/OpenELEC.tv · GitHub).
    There are a lot of services btw. on LibreElec JLjd4GV8

  • It's still a WIP. We have some workarounds but not a real solution yet. But there will be. Just be a bit patient, please.

    It might not get its way into Beta but hopefully in the final/stable version.

  • The closest thing to fix this issue was new service /storage/.config/system.d/kodi-reboot.service (shutdown.sh always gets reboot parameter):

    But for some reason it didn't work 100% reliably.

  • Could you tell me where the service actually is that you´re editing? So i could try it by myself as well.

    I have got a tip from systemD IRC, the guy thinks that the following line could help us.

    Code
    After=network-online.target

    Maybe you can try it?

  • Sorry but i have to disappoint you. I have tried it and reactivated my shutdown. sh with the following content:

    It´s not working with your script, cause it´s not shutting down the NAS. When i insert this line it does shut down the NAS, but LE won´t poweroff completely:

    Code
    After=network-online.target


    Going with the command directly and without the fuckme.sh doesn´t help me either.

    So i guess we are on the right path.

    Here are some pics from the TV:
    tmp_1763-img_20160427_175047-318025923.jpg
    tmp_1763-img_20160427_175055141486835.jpg

    Edit:
    I have changed the following line from your example as well:

    Code
    ExecStop=-/bin/sh -c ". /etc/profile; exec /bin/sh /storage/.config/shutdown.sh"

    With this change he won´t even shutdown the NAS and LE.

  • Like I wrote I didn't used existed kodi reboot service just to sure that something doesn't interfere with new service.

    That's why I used NEW service shutdown_with_net.service and NEW script shutdown_with_net.sh. This script is executed on reboot and shutdown and doesn't support arguments.

    Also I think your current shutdown. sh script has errors.

  • Ok got it. I filled the shutdown_with_net.sh with the content of the fuckme.sh and now it powers off everything as it should.

    Big thanks vpeter!!

    Is this permanent then? If so a hint in the Wiki would be nice, that if someone is running in the same direction and needs network from within the shutdown.sh is not getting into the same trouble as i did, don´t you think?


  • Is this permanent then? If so a hint in the Wiki would be nice, that if someone is running in the same direction and needs network from within the shutdown.sh is not getting into the same trouble as i did, don´t you think?

    Now that you are the first user let's test this and report if works as it should in a few days. Then we will see how to proceed.

    Edited once, last by vpeter (April 27, 2016 at 6:15 PM).

  • To run different things on reboot and shutdown this few lines can help:

    Code
    if /usr/bin/systemctl list-jobs | /bin/egrep -q 'reboot.target.*start' > /dev/null; then
      # reboot
    else
      # shutdown
    fi

  • To run different things on reboot and shutdown this few lines can help:

    Code
    if /usr/bin/systemctl list-jobs | /bin/egrep -q 'reboot.target.*start' > /dev/null; then
      # reboot
    else
      # shutdown
    fi

    I tried this, and somehow it is not working.-.
    The shutdown_with_net.sh is running, but if I try to put my command in the shutdown else branch it's not working..
    You got an Idea, that I should try?
    And thanks for that workaround^^