I wrote a script and a service to power down my external Seagate drive on shutdown. It worked the first time but when I restart my computer it won't activate. I always have to start it manually before shutdown, which defeats the purpose. Maybe someone here can help me making the service working in a way that always when I shutdown the computer it will also turn of the drive.
Script:
#!/bin/sh
disk_uuid="MY-UUID-PLACEHOLDER"
udisksctl unmount -b /dev/disk/by-uuid/${disk_uuid}
udisksctl power-off -b /dev/disk/by-uuid/${disk_uuid}
exit 0
Service file:
[Unit]
Description=Shut down external disks
DefaultDependencies=no
Before=shutdown.target reboot.target kexec.target halt.target
[Service]
Type=oneshot ExecStart=/usr/sbin/power-off-disk.sh
RemainAfterExit=yes
[Install]
WantedBy=halt.target kexec.target reboot.target shutdown.target
Logs from journalctl -u:
Feb 22 11:53:50 ace-desktop systemd[1]: Starting Shut down external disks...
Feb 22 11:53:50 ace-desktop power-off-disk.sh[9810]: Error connecting to the udisks daemon: GDBus.Error:org.freedesktop.DBus.Error.NoReply: Message recipient disconnected from message bus without replying
Feb 22 11:53:50 ace-desktop power-off-disk.sh[9880]: Error connecting to the udisks daemon: Error calling StartServiceByName for org.freedesktop.UDisks2: Transaction for udisks2.service/start is destructive (dev-sdb1.swap has 'stop' job queued, but 'start' is included in transaction).
Feb 22 11:53:50 ace-desktop systemd[1]: power-off-disk.service: Deactivated successfully.
Feb 22 11:53:50 ace-desktop systemd[1]: Finished Shut down external disks.
So I now edited my Service file:
[Unit]
Description=Shut down external disks
DefaultDependencies=no
Before=udisks2.service shutdown.target reboot.target halt.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/usr/sbin/power-off-disk.sh
RemainAfterExit=no
[Install]
WantedBy=shutdown.target reboot.target halt.target
It changes nothing though.
systemctl start power-off-disk
works, when activated manually, but not on shutdown.
Help would really be appreciated.