telegram_1814454711

@telegram_1814454711:nichi.co

12 messages · Page 1 of 1

telegram_1814454711
[Unit] Description=Spin Down External USB Drives on Shutdown BindsTo=%i.mount After=%i.mount [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/true ExecStop=/bin/sh -c '/opt/safe-eject/safe-eject --shutdown $(/usr/bin/systemctl show -p What --value %i.mount)' [Install] WantedBy=multi-user.target 最后这样弄了, 好像能用了😃, 就是要脚本里面再判断一下是关机还是重启 systemctl list-jobs | grep -q 'shutdown.target'
telegram_1814454711
这样应该就能做到了吧(
telegram_1814454711
哦是不是可以 Before=xxx.mount
telegram_1814454711
如果能做到关联那个mount unit, 在它之后启动就感觉能对上用了
telegram_1814454711
但是我不知道这个能不能做到是在挂载点之后再启动😢
telegram_1814454711
我有个想法是这样 ... BindsTo=xxx.mount [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/true ExecStop=/opt/safe-eject/safe-eject --shutdown ...
telegram_1814454711
停转指令下发本身我这边已经能用了, 但是我想控制一下它的触发时机, 同时保留systemd自己本身的卸载挂载点行为
telegram_1814454711
是不是更适合用 ExecStart=/bin/true, 然后用 BindsTo 绑定到挂载mount unit上, 在ExecStop那边写停转指令呀
telegram_1814454711
我想着让 systemd 正常做挂载点卸载, 在它卸载之后, 要插入一个停转指令下发的环节, 免得直接强制断电停转收回磁头了.
telegram_1814454711
我脚本里面用了 hdparm -Y "$dev" 和 sg_start --stop "$dev"
telegram_1814454711
* 问一个问题 我有使用USB硬盘盒, 当我电脑关机时, 硬盘盒里的HDD会强制断电停转. 我就写了一个脚本, 用于在关机时, 先向HDD下发停转指令. 这个脚本我想着使用 systemd unit 来做关机时自动调用. [Unit] Description=Spin Down External USB Drives on Shutdown DefaultDependencies=no After=umount.target Before=shutdown.target systemd-udev-trigger.service systemd-udevd.service [Service] Type=oneshot ExecStart=/opt/safe-eject/safe-eject --shutdown TimeoutStartSec=0 [Install] WantedBy=shutdown.target 我测试发现, 脚本是有效果, 但是这个 service 完全没有被 journal 记录了. $ journalctl -b -1 -u safe-eject.service -- No entries -- $ journalctl -rb -1 Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /root. Feb 15 12:24:14 UM690Lite systemd[1]: root.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /home. Feb 15 12:24:14 UM690Lite systemd[1]: home.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /docker. Feb 15 12:24:14 UM690Lite systemd[1]: docker.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /boot. Feb 15 12:24:14 UM690Lite systemd[1]: boot.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /.snapshots. Feb 15 12:24:14 UM690Lite systemd[1]: \x2esnapshots.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite kernel: EXT4-fs (sda1): unmounting filesystem 6686b8bf-0b7c-4b7c-969f-f3b5e76f1c9b. Feb 15 12:24:14 UM690Lite kernel: BTRFS info (device sdb1): last unmount of filesystem cca02f85-9304-46cf-9bf1-b67536061849 Feb 15 12:24:14 UM690Lite systemd[1]: Stopping Flush Journal to Persistent Storage... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/tmp... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/lib/docker... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/cache... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /usr/local... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting Temporary Directory /tmp... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /root... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /mnt/data... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /mnt/archive/insecure... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /home... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /docker... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /boot... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /.snapshots... Feb 15 12:24:14 UM690Lite systemd[1]: Stopped target Local File Systems. 而且我也没看到 Unmounting /var/log 如果我 systemd unit 不用 After=umount.target, 用 Before=umount.target ..., 日志是有的, 但我感觉会不会时机不太好, 那就需要我脚本内部做 umount 了😶‍🌫️
telegram_1814454711
问一个问题 我有使用USB硬盘盒, 当我电脑关机时, 硬盘盒里的HDD会强制断电停转. 我就写了一个脚本, 用于在关机时, 先向HDD下发停转指令. 这个脚本我想着使用 systemd unit 来做关机时自动调用. [Unit] Description=Spin Down External USB Drives on Shutdown DefaultDependencies=no After=umount.target Before=shutdown.target systemd-udev-trigger.service systemd-udevd.service [Service] Type=oneshot ExecStart=/opt/safe-eject/safe-eject --shutdown TimeoutStartSec=0 [Install] WantedBy=shutdown.target 我测试发现, 脚本是有效果, 但是这个 service 完全没有被 journal 记录了. $ journalctl -rb -1 Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /root. Feb 15 12:24:14 UM690Lite systemd[1]: root.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /home. Feb 15 12:24:14 UM690Lite systemd[1]: home.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /docker. Feb 15 12:24:14 UM690Lite systemd[1]: docker.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /boot. Feb 15 12:24:14 UM690Lite systemd[1]: boot.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite systemd[1]: Unmounted /.snapshots. Feb 15 12:24:14 UM690Lite systemd[1]: \x2esnapshots.mount: Deactivated successfully. Feb 15 12:24:14 UM690Lite kernel: EXT4-fs (sda1): unmounting filesystem 6686b8bf-0b7c-4b7c-969f-f3b5e76f1c9b. Feb 15 12:24:14 UM690Lite kernel: BTRFS info (device sdb1): last unmount of filesystem cca02f85-9304-46cf-9bf1-b67536061849 Feb 15 12:24:14 UM690Lite systemd[1]: Stopping Flush Journal to Persistent Storage... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/tmp... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/lib/docker... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /var/cache... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /usr/local... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting Temporary Directory /tmp... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /root... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /mnt/data... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /mnt/archive/insecure... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /home... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /docker... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /boot... Feb 15 12:24:14 UM690Lite systemd[1]: Unmounting /.snapshots... Feb 15 12:24:14 UM690Lite systemd[1]: Stopped target Local File Systems. 而且我也没看到 Unmounting /var/log 如果我 systemd unit 不用 After=umount.target, 用 Before=umount.target ..., 日志是有的, 但我感觉会不会时机不太好, 那就需要我脚本内部做 umount 了😶‍🌫️
Page 1 / 1

Matrix Historian — Message Archive Browser