Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide LED control on rpi 3B+ and 4B (moOde 6.4.2+)
#15
(04-20-2021, 12:30 PM)Britracer Wrote:
(04-19-2021, 08:29 AM)romain Wrote:
(04-19-2021, 03:26 AM)Britracer Wrote:
(04-07-2020, 01:01 PM)romain Wrote: Hello,

I've written a shell script which controls the behavior of the rpi LEDs depending on the availability of the configured sources and/or plugged in USB storage(s).

The script is called by a one shot systemd service unit started by a systemd timer unit every 1 minute after the last execution (thanks to philrandal for his advise), you can change this timing to suite your needs. It queries the local SQLITE db to fetch sources settings and tries to remount automatically configured sources if they become unavailable. Works with SMB, NFS, UPnP.

Version 6.5.0 users should turn off LED0 (Activity) and LED1 (Power) directly in the moOde interface (System -> Sytem Modifications) before enabling the systemd service and timer units. I also made some minor modifications to the shell script itself, new version attached here.

Red LED is off by default.
Fixed green LED means all sources configured and/or all plugged in USB storage(s) are available.
Blinking green LED means at least one configured source and/or one plugged in USB storage is unavailable if multiple sources have been configured or if multiple USB storage(s) are plugged in.
Fixed red LED means configured source(s) and/or plugged in USB storage(s) are unavailable.

The only small drawback is when NFS shares are hard mounted (default) ; you may want use soft NFS mounts instead otherwise the script will get stucked waiting for the NFS server to respond (normal behavior).

For NFS soft mounts you should use instead the mount flags:
Code:
soft,timeo=10,retrans=1,ro,nolock

You can also set these mount flags as default if you edit line 208 (version 6.4.2) or 222 (version 6.5.0) in file /var/www/js/scripts-configs.js in order to obtain:
Code:
$('#options').val('soft,timeo=10,retrans=1,ro,nolock');

File checksources.sh should be placed in /usr/local/sbin and made executable:
Code:
sudo chmod +x /usr/local/sbin/checksources.sh

File checksources.service should be placed in /etc/systemd/system and enabled to launch at startup:
Code:
sudo systemctl enable checksources.service

File checksources.timer should be placed in /etc/systemd/system and enabled to execute checksources.service every 1 minute after the last execution of the unit:
Code:
sudo systemctl enable checksources.timer

Start both systemd units:
Code:
sudo systemctl start checksources.service
Code:
sudo systemctl start checksources.timer
or reboot your system:
Code:
sudo shutdown -r now

To check the output of the script, check out syslog:
Code:
tail -f /var/log/syslog
or use:
Code:
journalctl -u checksources.service

I've tested it on pi 3B+ and 4B with moOde versions 6.4.2 and 6.5.0.

Zip file attached, feel free to use and improve if needed.

Wonder if you can help.
Just found your post and thought if would be a good fix for my NAS becoming unmounted randomly or after the router resets.
Implemented as you have it described and it worked great - only thing I noticed is it really bogged the system down and made the webinterface almost unusable - on a Pi3B+ also running an OLED using pydPiper

Rob

Hello Rob,

I hadn't retried my script with the latest version of moOde. I've just noticed that mountpoint now behaves differently and gets indefinitely stuck if a mountpoint becomes unavailable.

To fix this, in function called checkMount of /usr/local/sbin/checksources.sh, replace 
Code:
/bin/mountpoint -q "${1}"
with
Code:
timeout 1 /bin/mountpoint -q "${1}"

Code:
timeout 1 stat -t "${1}" > /dev/null 2>&1
It's on line 17 in my version of the script.

Let me know if it helps.

Thank you I will give it a go.
Appreciate you looking into this for me.

OK, disregard the line with 
Code:
timeout 1 stat -t "${1}" > /dev/null 2>&1
it should be 
Code:
timeout 1 /bin/mountpoint -q "${1}"
instead
Reply


Messages In This Thread
RE: LED control on rpi 3B+ and 4B (moOde 6.4.2+) - by romain - 04-20-2021, 12:35 PM

Forum Jump: