How to restart rc.local after reboot of linino

In case a infinitly looping python script crashes/fails, I want the mcu and linino to reboot.
The script is started in /etc/rc.local and runs infinitly, if it crashes/fails first mcu-restart
and then linino reboot are executed-

BUT after the reboot the linino won't restart the /etc/rc.local at all (tested with ssh by typing "reboot")...
It seems that only after a power loss rc.local is executed.

What can I do to automatically execute rc.local after a reboot of linino?

in case it helps, here is my /etc/rc.local (working fine when cutting power and replugging):

sleep 50
/usr/bin/internet-live-led &     # A script constantly checking for internet connection
                                                      # in the background and blinking wifi led if internet is up.
                                                      # And it deactivates wifi and reactivates it, if internet is down
sleep 15
python /mnt/sd/MyScript.py       # MY infinitly looping SCRIPT uploading data if internet is up
                                                          # else its waiting for the internet to reconnect

/usr/bin/reset-mcu                  # rebooting arduino-processor if somehow myscript crashed

reboot                                       # rebooting linino

exit 0

In my case, scripts in /etc/rc.local run properly after reboot (I type "reboot" in ssh to trigger that). You may try to move your Python file to another location (e.g., under /root). Maybe there is some timing issue with mounting the SD card even with the sleep commands there.

Just my 2 cents.

Things I tried:

  • I put my script in the root-folder
  • longer sleep (75 s) at the beginning of the /etc/rc.local
  • put wifi-led-blinking ( /usr/bin/blink-start 100 ) into
    the beginning (line after "sleep 75") of the /etc/rc.local
    ( to see if that starts and maybe my scripts aren't working...)

Still no luck :frowning: The yun is ON, everything is ON (wifi ON and connected, web interface accessable, ...) ...
BUT the wifi-led isn't blinking, the scripts aren't running.... somehow "reboot" doesn't start rc.local at all after booting...

I'm frustrated...

this is how my rc.local looks now:

sleep 75

/usr/bin/blink-start 100
sleep 2
/usr/bin/internet-live-led &

sleep 15
python /root/TempPlotly.py          # my infinitly looping script

/usr/bin/reset-mcu

sleep 50
reboot

exit 0

Adding "reboot" to the end of /etc/rc.local is most probably a bad idea. :slight_smile:

I suggest to add "&" to the end of your Python call. Make it like

python /root/TempPlotly.py &

In your current case, if TempPlotly.py runs indefinitely, the following "reset-mcu" will never be called. Adding "&" runs the Python script at the background.

Yes, that was the intention! ONLY if somehow my script crashes the mcu-reset and reboot shall be executed. Thats why I don't put a "&" behind the script. I assumed that the rc.local continues with the next line if my infinit script crashes, doesn't it?!

By the way:
I have circumvented most of my [internet (re-)connection/script/reboot/wifi/...] problems by...

  1. ... leaving out/uncommenting "wifi-live-or-reset" from /etc/rc.local
  2. ... putting a try/exception (for many Errors like IOError, requests, http,...) into the infinitly looping "while" of my Python-Script
  3. ... putting my script directly onto my /root folder (not on the SD-card anylonger)
  4. ... doing as much on the linino-side as possible ( = replacing as much sketch-code as possible and using python and shell-scripts instead)
  5. ... using the dhcp-patch (= adding a missing line into the dhcp-file of the arduino... a known openwrt-issue)
  6. ... configuring only ONE wifi/WAN network with luci, sticking to it and by leaving the "replace wifi settings"-option checked during wifi-set-up

Now (almost) everything works as intended. Thanks for your help !

Thats why I don't put a "&" behind the script. I assumed that the rc.local continues with the next line if my infinit script crashes, doesn't it?!

Oh, now I see your intention of missing out "&". Very smart idea. Glad to learn a new nice trick. :slight_smile: On the other hand, need to be careful using it though as the system may keep rebooting in some unexpected scenarios.

In my designs, I usually have the cloud to detect any abnormal behavior (e.g., no sending sensor data any more) and let the cloud trigger reboot remotely.

using the dhcp-patch (= adding a missing line into the dhcp-file of the arduino... a known openwrt-issue)

I am interested in this DHCP patch. Wonder if you can share a link?

Congratulations on your progress!

Of course, here you got it:

By the way: How do you reboot the yun remotely? I’m especially interested in the command(s) you use.
Or do you have a link?

By the way: Here is how I solved this issue!

The order of the reboots (32u4 and linino) is very important!
My false order prevented the Bridge to initialize, because I rebooted the mcu BEFORE I rebooted the linino...
Now I solved my reboot issue this way with the rc.local:

sleep 5
# Reset the 32u4 ALWAYS right when the linino is ready. This way, after some crash the bridge etc get reinitialized automatically:
/usr/bin/reset-mcu
sleep 25
/usr/bin/blink-start 50
sleep 2
/usr/bin/blink-stop
/opt/python/bin/python /root/TempPlotly.py

# If the infinitly looping script somehow terminates reboot:
reboot   
        
exit 0

Now, if my infinitly looping script somehow crashes everything reboots automatically as expected