From c33c05ae679a8c7924de11ae51030a1eb3a65cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Berthold=20H=C3=B6llmann?= Date: Thu, 12 Jun 2025 04:14:48 +0200 Subject: [PATCH] Add support for setting power LED via systemctl (#60) * Add support for setting power LED via systemctl * Add documentation for rudimentary ugreen-power-led.service * Add "Type=oneshot" and "RemainAfterExit=true" as suggested --- README.md | 2 ++ scripts/systemd/ugreen-power-led.service | 13 ++++++++++ scripts/ugreen-leds.conf | 14 +++++++++++ scripts/ugreen-power-led | 30 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 scripts/systemd/ugreen-power-led.service create mode 100644 scripts/ugreen-power-led diff --git a/README.md b/README.md index 5f357bf..b2377af 100644 --- a/README.md +++ b/README.md @@ -210,11 +210,13 @@ Please see `scripts/ugreen-leds.conf` for an example. # change enp2s0 to the network device you want to monitor systemctl start ugreen-netdevmon@enp2s0 systemctl start ugreen-diskiomon + systemctl start ugreen-power-led # if you confirm that everything works well, # run the command below to make the service start at boot systemctl enable ugreen-netdevmon@enp2s0 systemctl enable ugreen-diskiomon + systemctl enable ugreen-power-led ``` - (_Optional_) To reduce the CPU usage of blinking LEDs when disks are active, you can enter the `scripts` directory and do the following things: diff --git a/scripts/systemd/ugreen-power-led.service b/scripts/systemd/ugreen-power-led.service new file mode 100644 index 0000000..284175e --- /dev/null +++ b/scripts/systemd/ugreen-power-led.service @@ -0,0 +1,13 @@ +[Unit] +Description=UGREEN LEDs daemon for configuring power LED +After=ugreen-probe-leds.service +Requires=ugreen-probe-leds.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/ugreen-power-led +RemainAfterExit=true +StandardOutput=journal + +[Install] +WantedBy=multi-user.target diff --git a/scripts/ugreen-leds.conf b/scripts/ugreen-leds.conf index 0a59491..f9a8605 100644 --- a/scripts/ugreen-leds.conf +++ b/scripts/ugreen-leds.conf @@ -110,3 +110,17 @@ COLOR_NETDEV_LINK_10000="255 255 255" # color of the netdev when unable to ping the gateway COLOR_NETDEV_GATEWAY_UNREACHABLE="255 0 0" + +# =========== parameters for power LED =========== + +# Blink settings for the power LED +# * none: no blinking (default) +# * breath : breathing blink +# * blink : blinking +BLINK_TYPE_POWER="none" + +# brighness of the power LED (default: 255) +BRIGHTNESS_POWER=255 + +# color of the power LED (default: 255 255 255) +COLOR_POWER="255 255 255" diff --git a/scripts/ugreen-power-led b/scripts/ugreen-power-led new file mode 100644 index 0000000..06659c7 --- /dev/null +++ b/scripts/ugreen-power-led @@ -0,0 +1,30 @@ +#!/usr/bin/bash + +# use variables from config file (unRAID specific) +if [[ -f /boot/config/plugins/ugreenleds-driver/settings.cfg ]]; then + source /boot/config/plugins/ugreenleds-driver/settings.cfg +fi + +# load environment variables +if [[ -f /etc/ugreen-leds.conf ]]; then + source /etc/ugreen-leds.conf +fi + +# Blink settings for the power LED +# * none: no blinking +# * breath : breathing blink +# * blink : blinking +BLINK_TYPE_POWER=${BLINK_TYPE_POWER:="none"} + +# brighness of the power LED +BRIGHTNESS_POWER=${BRIGHTNESS_POWER:=255} + +# color of the power LED +COLOR_POWER=${COLOR_POWER:="255 255 255"} + +# initialize LEDs +if [[ -d /sys/class/leds/power ]]; then + echo "$BLINK_TYPE_POWER" > /sys/class/leds/power/blink_type + echo "$BRIGHTNESS_POWER" > /sys/class/leds/power/brightness + echo "$COLOR_POWER" > /sys/class/leds/power/color +fi