How To Execute a Script at Shutdown/Halt on Raspbian Stretch
Posted: Fri Feb 08, 2019 9:21 am
Hi All,
I'm using a Raspberry pi 3B+ within Raspian Strecth 9.6.
I need to execute a script that send a command on serial ttyACM0 to switch-off raspberry power-supply, when the command "sudo poweroff" or "sudo halt" are issued.
The source script is visible below:
I tried to use systemd placing a service script on /lib/systemd/system/mypoweroff.service, enable it using
but it seems doesn't work.
I googled for a solution, but until now I have not found anything working.
Do you have any suggestions for me ?
Thank you.
I'm using a Raspberry pi 3B+ within Raspian Strecth 9.6.
I need to execute a script that send a command on serial ttyACM0 to switch-off raspberry power-supply, when the command "sudo poweroff" or "sudo halt" are issued.
The source script is visible below:
Code: Select all
[Unit]
Description=Turn power off after shutdown
DefaultDependencies=no
Before=umount.target
[Service]
Type=oneshot
ExecStart=/bin/echo "cmd=switchoff" > /dev/ttyACM0
[Install]
WantedBy=halt.target poweroff.target
Code: Select all
systemctl enable mypoweroff.service
I googled for a solution, but until now I have not found anything working.
Do you have any suggestions for me ?
Thank you.