我編寫了一個腳本和一個服務來在關機時關閉我的外部希捷硬碟。它第一次工作,但當我重新啟動電腦時,它不會啟動。我總是必須在關閉之前手動啟動它,這達不到目的。也許這裡有人可以幫助我使該服務以一種當我關閉電腦時它也會關閉驅動器的方式工作。
腳本:
#!/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
服務文件:
[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
來自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.
所以我現在編輯我的服務文件:
[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
但它什麼也改變不了。
systemctl 啟動磁碟斷電
手動啟動時有效,但關機時無效。非常感謝您的幫忙。