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):
/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
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
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.
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 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...
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...
... leaving out/uncommenting "wifi-live-or-reset" from /etc/rc.local
... putting a try/exception (for many Errors like IOError, requests, http,...) into the infinitly looping "while" of my Python-Script
... putting my script directly onto my /root folder (not on the SD-card anylonger)
... doing as much on the linino-side as possible ( = replacing as much sketch-code as possible and using python and shell-scripts instead)
... using the dhcp-patch (= adding a missing line into the dhcp-file of the arduino... a known openwrt-issue)
... 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. 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?
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:
# Reset the 32u4 ALWAYS right when the linino is ready. This way, after some crash the bridge etc get reinitialized automatically:
# If the infinitly looping script somehow terminates reboot:
Now, if my infinitly looping script somehow crashes everything reboots automatically as expected