Page 1 of 1

How to add a custom command when shutting down the Pi?

Posted: Sat Feb 16, 2019 1:34 pm
by Cr4z33
I need to add a command line ONLY IF shutting down (NOT when rebooting) the Pi.

Can someone please tell me how to do that? :)

Re: How to add a custom command when shutting down the Pi?

Posted: Sat Feb 16, 2019 1:40 pm
by davidcoton

Re: How to add a custom command when shutting down the Pi?

Posted: Sat Feb 16, 2019 3:25 pm
by Cr4z33
Thanks for the link, but I am still quite confused on what is the best solution for me. :oops:

Basically all I want is to run

Code: Select all

echo standby 0 | cec-client -s -d 1
right after I click the LXDE shutdown button.

First of all does it have to look like the following?

Code: Select all

[Unit]
Description=Run CEC command to turn the TV off
DefaultDependencies=no
Before=umount.target

[Service]
Type=oneshot
ExecStart=echo standby 0 | cec-client -s -d 1

[Install]
WantedBy=poweroff.target halt.target
I saved it as /lib/systemd/system/cec-shutdown.service

Rebooted and then shutdown the Pi, but the TV keeps staying on... :?