I am really hoping to find some advice here. I am trying to setup a service in systemd that executes a .sh script at shutdown (and only at shutdown, halt and/or poweroff; NOT at reboot) of the the Pi. The service script is located in
Setup: Raspberry Pi 2 with OSMC 2016.10-1 (linux kernel 4.4.27-2-osmc). So far, I stumbled around the web and found some snippets to setup the service as follows:
[Unit] Description=executed at shutdown Conflicts=reboot.target After=network.target [Service] Type=oneshot ExecStart=/bin/true ExecStop=/path/to/script RemainAfterExit=yes [Install] WantedBy=multi-user.target
But I simply lack the necessary knowledge of systemd and how to execute a bash script within this service to get it properly running.
As starting point, I have created a simple script
test_script.sh to check, if the service is running as expected and executes the script right before shutdown:
#!/bin/sh echo 'the script is executed' > test.txt
it's located in the /home directory and executable after
Using the command
executes this script as expected and the file is created. But once the service is setup and enabled using systemctl, the script seems not to be executed before shutdown of the Pi.
What is going wrong here? Maybe there is someone who can point me in the right direction. I would really appreciate any help - many thanks in advance!