OnionUI / Onion

OS overhaul for Miyoo Mini and Mini+
https://onionui.github.io
GNU General Public License v3.0
3.16k stars 190 forks source link

Checkoff scripts closed in 1 minute #1562

Closed Nerqs closed 1 month ago

Nerqs commented 2 months ago

Checklist

Onions OS Version

4.3.0

Miyoo Firmware Version

202306282128

Provide a clear and concise description of the issue

I wrote a script in checkoff directory, but when i power off my miyoo mini plus this script is only running for 1 minute, after this the system force a power off. I have tried my script in another dispositives and it works just fine.

Steps to Reproduce

Make a script that keeps running more than a minute and put it in the checkoff directory.

Provide any additional context or information that may help us investigate your issue

The shutdown function appears to be executed and scheduled before starting the scripts in the checkoff directory.

XK9274 commented 1 month ago

What's your script doing?

Nerqs commented 1 month ago

What's your script doing?

A backup script, but the system force a shutdown before this script finishes.

XK9274 commented 1 month ago

Surely if it's a backup script it's not trying to backup the whole unit every time you shutdown is it?

What files are you moving?

Nerqs commented 1 month ago

No, the script just upload the Saves/CurrentProfile folder to the cloud.

XK9274 commented 1 month ago

How many saves do you have lol.

How's your script setup? Ideally for all these files before moving them you should tar.gz the directory and move that up to the cloud instead as it'll be faster.

Edit: or use 7zip

Can't see otherwise how it would take over a minute to move files less than a meg each

Nerqs commented 1 month ago

This is a good idea, but I've already resolved the file size issue. My question is whether there is a way to increase the time that the system forces shutdown or cancel this function, because if I try to include other scripts this function will prevent them from working.

Aemiii91 commented 1 month ago

Maybe the sleep timer is being triggered? You can try to get around this by setting the flag /tmp/stay_awake.

XK9274 commented 1 month ago

I've just tried this and i don't even get 60 seconds:

Script has been running for 0 seconds.
Script has been running for 1 seconds.
Script has been running for 2 seconds.
Script has been running for 3 seconds.
...
Script has been running for 27 seconds.
Script has been running for 28 seconds.
Script has been running for 29 seconds.
Script has been running for 30 seconds.

But with some small changes you get this:

Script has been running for 0 seconds.
Script has been running for 1 seconds.
Script has been running for 2 seconds.
Script has been running for 3 seconds.
...
Script has been running for 54 seconds.
Script has been running for 55 seconds.
Script has been running for 56 seconds.
Script has been running for 57 seconds.

This is a dirty fix but, can you try replacing your check_off_order function in runtime.sh with:

check_off_order() {
    if [ -f /tmp/.offOrder ]; then
        # EmuDeck - CheckOff scripts
        check_off_scripts=$(find "$sysdir/checkoff" -type f -name "*.sh")

        for check_off_script in $check_off_scripts; do
            touch /tmp/wait_to_shutdown
            sh "$check_off_script"
            rm -rf /tmp/wait_to_shutdown
        done

        bootScreen "$1" &
        sleep 1 
        shutdown
    fi
}

And in .tmp_update/bin/shutdown add at the very top:

if [ -f /tmp/wait_to_shutdown ]; then
    exit 0
fi

image

Here's a test script:

#!/bin/sh

start_time=$(date +%s)

while true; do
    current_time=$(date +%s)
    elapsed_time=$((current_time - start_time))

    echo "Script has been running for $elapsed_time seconds."

    if [ $elapsed_time -ge 85 ]; then
        echo "Script has completed its 85-second runtime."
        break
    fi

    sleep 1
done
.....
Script has been running for 84 seconds.
Script has been running for 85 seconds.
Script has completed its 85-second runtime.

The script will run for 85 seconds, then the device should shutdown

XK9274 commented 1 month ago

I just want to add this is a diag dirty fix and shouldn't be used by anyone else until we have a proper fix in place. It seems shutdown is being called twice and the forced call still runs, which is why your device shuts down during execution of the script

Edit for clarity: Keymon has a kill switch if the device hangs, it's not technically running twice but a forced call is used after a certain amount of time to address crashes

Nerqs commented 1 month ago

Thank you very much for the answers, i made the changes and it worked perfectly.

XK9274 commented 1 month ago

Thanks for letting us know, we've found what's causing it so it'll be fixed :)