dea*_*sin 3 shutdown scripts upstart systemd 15.10
我有一个备份脚本~/scripts/backup.sh
和我的暴发户conf ~/.config/upstart/shutdown.conf
。
description "my shutdown script"
start on desktop-end
task
console log
script
exec ~/scripts/backup.sh start
end script
Run Code Online (Sandbox Code Playgroud)
我的脚本备份到外部硬盘驱动器on desktop-end
,但在调用我的脚本之前外部硬盘驱动器被卸载。
如何在关闭序列之前使用我的脚本,然后仅在脚本完成时恢复?
我尝试了这篇文章中的解决方案,但挂钩on starting rc
不起作用。
谢谢。
归功于此发布的答案
首先,我不知道为什么 upstart 可以工作,因为 Ubuntu 15.10 应该使用 systemd。所以我使用systemd来解决我的问题。
我创建了一个名为 backup.service 的 systemd“单元”
[Unit]
Description=Backup script
DefaultDependencies=no
RequiresMountsFor=/mnt/D21EF5DA1EF5B795 /home /media/external
Before=shutdown.target reboot.target halt.target
[Service]
ExecStart=/bin/bash /home/deanresin/scripts/backup.sh start
Type=oneshot
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
RequiresMountsFor
确保这些硬盘驱动器在脚本之前和期间保持安装状态。 Before=shutdown.target reboot.target halt.target
是将调用备份脚本的钩子。
将 backup.service 文件放入 /etc/systemd/system 并sudo chmod u+x /etc/systemd/system/backup.service
使其可执行。
现在启用 backup.servicesystemctl enable backup.service
瞧!备份脚本“backup.sh”应在重新启动、关闭或暂停时调用,并在卸载指定驱动器之前执行。