systemd 在(每个)挂载上执行脚本 [英] systemd execute script on (every) mount

查看:69
本文介绍了systemd 在(每个)挂载上执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次与 systemd 纠缠不清,无法真正让它按照我的需要运行,已经通过 Google 和手册页进行了深入研究,但没有运气..

我需要在每次插入 USB 闪存驱动器时执行一个脚本(下一步是在移除驱动器时也运行一个脚本.. 但首先要做的是..)

我只能让它触发一次,或者在只要驱动器保持连接的情况下运行的循环中触发(幸运的是很快失败并出现启动限制错误).我无法让它仅在插入时运行,并在每次新插入时运行.

[单位]说明=USB 连接触发器RequiresMountsFor=/media/usb[服务]类型=oneshotExecStart=/home/hu/hu_restart.sh

我一直在玩不同的类型和重启选项,但没有运气..hu_restart.sh 只是一个运行和存在的脚本,它不会保持活动状态.

有人吗?

一些背景:我有一个脚本运行某种汽车主机",需要知道 USB 驱动器是否可用(或不可用)来更改音乐源".hu_restart.sh 是一个重新启动主机脚本的黑客.启动时,它会检查 USB 是否可用并从那里开始播放.

解决方案

无法让它工作.但是使用 udisks-glue 可以很好地工作.我相信我在某处读到 udisks-glue 已被弃用.可能是这样,但效果很好!

我认为在这里描述这个不同的选项超出了范围(但是,如果有人想知道,我很乐意解释).

I'm tangling with systemd for the first time and cannot really get it to run as I need it, already plowed through Google and the man pages, but no luck..

I need to execute a script every time a USB flash drive is inserted (next step would be to also run a script when the drive is removed.. but first things first..)

I can only get it trigger once, or to trigger in a loop (which luckily quickly fails with a start-limit error) that runs as long as the drive remains connected. I cant get it to only run when it is inserted, and run on every next new insertion.

[Unit]
Description=USB connected trigger
RequiresMountsFor=/media/usb

[Service]
Type=oneshot
ExecStart=/home/hu/hu_restart.sh

I've been playing around with different types and restart options, but no luck.. hu_restart.sh is just a script that runs and exist, it doesn't remain active.

Anyone?

Some background: I've a script running some kind of car "head unit" that needs to know that an USB drive is available (or not) to change the music "source". The hu_restart.sh is a bit of a hack that restarts the head unit script. On start it checks if USB is available and starts playback from there or not.

解决方案

Couldn't get this to work. But this works quite well using udisks-glue. I believe I read somewhere udisks-glue is deprecated. That may be the case, but it works very well!

I think it goes beyond the scope to describe this different option here (but, if someone wants to know, I'd be happy to explain).

这篇关于systemd 在(每个)挂载上执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆