1

I am trying to get my raspberry pi 3 (running Raspbian 10) to show an animation on boot and before shutdown/reboot.

using Plymouth I managed to get the boot animation, however, it doesn't display anything on reboot/shutdown. So I wrote a small shell script and linked it with systemd services to show the animation before shutdown.target reboot.target.

here is what I tried:

/etc/systemd/system/run2.service :

[Unit]
Description=Run a script at shutdown
Before=multi-user.target

[Service]
RemainAfterExit=yes
ExecStop=/lib/systemd/system-shutdown/test.sh

[Install]
WantedBy=multi-user.target

for the Before=.. I also tried Before=shutdown.target reboot.target and Before=plymouth.target, they have the same result as explained above.

/lib/systemd/system-shutdown/test.sh :

#! /bin/bash
sudo plymouthd
sudo plymouth show-splash
sudo sleep 5
sudo touch /home/pi/Desktop/test

then:

sudo chmod 644 /etc/systemd/system/run2.service
sudo chmod +x  /lib/systemd/system-shutdown/test.sh


sudo systemctl enable run2.service

on each restart, the file test is created on the desktop but right after a reboot or shutdown now command but the screen goes blank without showing any animation.

can anybody give a newbie explanation on this subject?

Thanks

Ingo
  • 42,961
  • 20
  • 87
  • 207
Behnam Ezazi
  • 43
  • 1
  • 7

1 Answers1

2

Your service file looks good, except for the Before=multi-user.target line. That should be After=multi-user.target, because services get stopped in the inverted order they got started.

There's no need for ExecStart= or Type= as you can find the following in the manual pages:

Type=oneshot is the implied default if neither Type= nor ExecStart= are specified.

and

When Type=oneshot is used, zero or more commands may be specified.

To troubleshoot your problem add exec &>> /var/log/run2.log as the second line to your script and some echos. This will redirect all output to a file (/var/log/run2.log) so that you can possibly see what has gotten wrong.

I tested it with following script

#!/bin/bash
exec &>> /home/pi/test.log
date
echo "shutdown"
sleep 2
echo "slept 2 seconds"
sleep 3
echo "slept another 3 seconds"

and after a reboot I found that test.log existed and contained:

Do 8. Aug 12:35:24 BST 2019 
shutdown
slept 2 seconds 
slept another 3 seconds
jake
  • 1,367
  • 1
  • 11
  • 23