The following is a quick guide on getting basic status LED functionality working with TrueNAS running on the UGREEN DXP4800 Plus. Theoretically, it should work on all models (with some small revisions to the script), but I only have a DXP4800 Plus. :)
This guide is for cron job that runs a script to update the LEDs every couple minutes, but I'm sure the following can be modified for blinky LEDs as well.
- Manually build or download the
ugreen_leds_cli
tool from https://github.com/miskcoo/ugreen_dx4600_leds_controller. - Plop it somewhere on your NAS (E.g. a dataset).
- In the same dataset, create your
.sh
script that controls the LEDs. At the bottom of this gist is my modified version of meyergru's. - Make the script executable:
chmod +X your-script.sh
.- You may also need to make
ugreen_leds_cli
executable as well.
- You may also need to make
- In TrueNas, navigate over to
System Settings
→Advanced
- Under
Init/Shutdown Scripts
Create the following to load thei2c-dev
module on boot:- Description:
Enable i2c-dev
- Type:
Command
- Command:
modprobe i2c-dev
- When:
Pre Init
- Description:
- Under
Cron Jobs
we then create a task to run every x minutes:- Description:
Update Status LEDS
- Command:
/mnt/path/to/your/script.sh
- Run as User:
root
- Schedule:
*/5 * * * *
(or however often you desire)
- Description:
- Reboot and wait a bit for your cron job to run.
- https://github.com/miskcoo/ugreen_dx4600_leds_controller
- https://github.com/meyergru/ugreen_dxp8800_leds_controller
#! /bin/bash
#set -x
SCRIPTPATH=$(dirname "$0")
echo $SCRIPTPATH
devices=(p n x x x x)
map=(power netdev disk1 disk2 disk3 disk4)
# Check network status
gw=$(ip route | awk '/default/ { print $3 }')
if ping -q -c 1 -W 1 $gw >/dev/null; then
devices[1]=u
fi
# Map sdX1 to hardware device
declare -A hwmap
echo "Mapping devices..."
while read line; do
MAP=($line)
device=${MAP[0]}
hctl=${MAP[1]}
partitions=$(lsblk -l -o NAME | grep "^${device}[0-9]\+$")
for part in $partitions; do
hwmap[$part]=${hctl:0:1}
echo "Mapped $part to ${hctl:0:1}"
done
done <<< "$(lsblk -S -o NAME,HCTL | tail -n +2)"
# Print the hwmap for verification
echo "Hardware mapping (hwmap):"
for key in "${!hwmap[@]}"; do
echo "$key: ${hwmap[$key]}"
done
# Check status of zpool disks
echo "Checking zpool status..."
while read line; do
DEV=($line)
partition=${DEV[0]}
echo "Processing $partition with status ${DEV[1]}"
if [[ -n "${hwmap[$partition]}" ]]; then
index=$((${hwmap[$partition]} + 2))
echo "Device $partition maps to index $index"
if [ ${DEV[1]} = "ONLINE" ]; then
devices[$index]=o
else
devices[$index]=f
fi
else
echo "Warning: No mapping found for $partition"
fi
done <<< "$(zpool status -L | grep -E '^\s+sd[a-h][0-9]')"
# Output the final device statuses
echo "Final device statuses:"
for i in "${!devices[@]}"; do
echo "$i: ${devices[$i]}"
case "${devices[$i]}" in
p)
"$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 255 255 255 -on -brightness 64
;;
u)
"$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 255 255 255 -on -brightness 64
;;
o)
"$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 0 255 0 -on -brightness 64
;;
f)
"$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 255 0 0 -blink 400 600 -brightness 64
;;
*)
"$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -off
;;
esac
done
same here.
Changed zpool to /sbin/zpool in the script.
the cli got rwxrwxrwx
it worked before i updated to the new stable TrueNas.
Ugreen DXP4800 Plus
TrueNas Scale ElectricEel-24.10.1
But now i get this:
Mapping devices...
Mapped sda1 to 0
Mapped sdb1 to 1
Mapped sdc1 to 2
Mapped sdd1 to 3
Hardware mapping (hwmap):
sda1: 0
sdd1: 3
sdb1: 1
sdc1: 2
Checking zpool status...
Processing sda1 with status ONLINE
Device sda1 maps to index 2
Processing sdb1 with status ONLINE
Device sdb1 maps to index 3
Processing sdc1 with status ONLINE
Device sdc1 maps to index 4
Processing sdd1 with status ONLINE
Device sdd1 maps to index 5
Final device statuses:
0: p
sudo: process 187901 unexpected status 0x57f
./led.sh: line 60: 187901 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 255 255 255 -on -brightness 64
1: u
sudo: process 187902 unexpected status 0x57f
./led.sh: line 60: 187902 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 255 255 255 -on -brightness 64
2: o
sudo: process 187903 unexpected status 0x57f
./led.sh: line 60: 187903 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 0 255 0 -on -brightness 64
3: o
sudo: process 187904 unexpected status 0x57f
./led.sh: line 60: 187904 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 0 255 0 -on -brightness 64
4: o
sudo: process 187905 unexpected status 0x57f
./led.sh: line 60: 187905 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 0 255 0 -on -brightness 64
5: o
sudo: process 187906 unexpected status 0x57f
./led.sh: line 60: 187906 Killed "$SCRIPTPATH/ugreen_leds_cli" ${map[$i]} -color 0 255 0 -on -brightness 64