So you have a Raspberry Pi 3 or 4 and been messing around the house with it. Perhaps you are using it “headless” like me through SSH. Quickly you probably realized the default behavior of the leds are quite useless: The red power led stays on even after shutdown, the green ACT led blinks even after the Pi has shut down as well and the GPIO power pins still supply power to whatever’s using it.
Well, turns out you can control the 2 LEDs on the Raspberry Pi’s board so I went ahead and made a small SystemD service that runs when the system has completely shut down. The service makes the red LED blink at max brightness and turns off the green LED so that you don’t see it blinking in the afterlife.
Keep in mind that once the Pi is completely off, there’s kind of a reset that happens on the LEDs (by the firmware I suppose) that puts the red LED back on solid.
First, we need to create 2 files on your Raspberry Pi:
1 2 touch led-poweroff.sh touch led-poweroff.service
Using the text editor of your choice on your Raspberry Pi (I love Vim), you’ll need to write these few lines into them.
1 2 3 4 5 6 #!/bin/bash echo 1 > /sys/class/leds/led1/brightness echo heartbeat > /sys/class/leds/led1/trigger echo 0 > /sys/class/leds/led0/brightness echo none > /sys/class/leds/led0/trigger sleep 3
1 2 3 4 5 6 7 8 9 10 11 [Unit] Description=Blink power led on completed shutdown DefaultDependencies=no Before=final.target [Service] Type=oneshot ExecStart=/bin/bash /root/led-poweroff.sh [Install] WantedBy=systemd-halt.service systemd-poweroff.service
Save those 2 files. Good.
Now let’s install them so they actually do something. Here’s how with a few commands on Raspberry Pi’s command line:
1 2 3 4 5 6 sudo cp led-poweroff.sh /root/. sudo chown root:root /root/led-poweroff.sh sudo chmod 500 /root/led-poweroff.sh sudo cp led-poweroff.service /etc/systemd/system/. sudo systemctl daemon-reload sudo systemctl enable led-poweroff.service
And…. that’s it!
Try it out on your Raspberry Pi using the classic poweroff command:
1 sudo poweroff
That’ll be all for today. Tell me in the comments how it went and if you did make some tweaks to it!