Run script with systemd before restart or shutdown

All kinds of 'OS' scripts
Post Reply
User avatar
Egregius
Posts: 2696
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Run script with systemd before restart or shutdown

Post by Egregius » Saturday 13 January 2018 15:33

Hi Folks,

I'd like to execute a bash script before my system is rebooted or does a shutdown.
I would need it on several systems:
a) On Domoticz running in Debian to store PHP APCu variables to disk so they can be recovered after boot.
b) To transfer camera records of pikrellcam from raspberry to nas.

These are my systemd config files:

Code: Select all

[Unit]
Description=Saves cache upon reboot and shutdown
After=apache2.service
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/var/www/html/secure/atreboot.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Code: Select all

[Unit]
Description=Saves video's on nas upon reboot and shutdown
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/home/pi/sync2nas.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Both are executed at shutdown (checked with a echo to logfile), so far so good.
Problem is that on the Domoticz system the APCu isn't available anymore because apache2 and php-fpm are already stopped.
For the raspberries the script is executed as long as the nas is online. As soon as the sync script needs to wake the nas with wol it takes to long and it isn't finished before reboot.

Any ideas?

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest