[systemd-devel] Starting systemd service in udev rule via ENV{SYSTEMD_WANTS} - help needed
Mirco Tischler
mt-ml at gmx.de
Sun Nov 18 06:37:20 PST 2012
2012/11/18 Warpme <warpme at o2.pl>
> Well,
> Things pretend to be simple seems to be not simple
> After 2 days of fighting with issue I have to ask for help.
> I want to kick systemd service when usb HDD is plugged.
> As started service needs to know HDD label I wan to use templates.
> Here is what it goes:
>
> udev rule:
> SUBSYSTEM=="block", KERNEL=="sd[c-z][0-9]", GOTO="begin"
> GOTO="end"
> LABEL="begin"
> ACTION=="add", GOTO="begin_add"
> ACTION=="remove", GOTO="begin_remove"
> GOTO="end"
>
> LABEL="begin_add"
> SYMLINK+="usbhd-%k", GROUP="root"
> ENV{ID_FS_LABEL_ENC}="usbhd-%**k"
> IMPORT{program}="/sbin/blkid -o udev -p $tempnode"
> ENV{ID_FS_LABEL_ENC}==".myth.**backup", ENV{MOUNT_DIR}="/media/$env{**ID_FS_LABEL_ENC}",
> RUN+="/bin/mkdir -p $env{MOUNT_DIR}", RUN+="/bin/mount -t auto -o
> rw,noauto,noatime /dev/%k $env{MOUNT_DIR}"
> ENV{ID_FS_LABEL_ENC}==".myth.**backup", TAG+="systemd",
> ENV{SYSTEMD_WANTS}="ext-usb-**backup.service"
> GOTO="end"
>
>
>
> service file:
> [Unit]
> Description=MythtTV ExtUSB Backup Helper
>
> [Service]
> ExecStart=/usr/local/bin/run-**backup.sh
> Type=forking
> GuessMainPID=false
> RemainAfterExit=no
>
>
>
> Issue:
> it works with:
> ENV{ID_FS_LABEL_ENC}==".myth.**backup", RUN+="/usr/bin/systemctl start
> ext-usb-backup.service"
>
> but not works with:
> ENV{ID_FS_LABEL_ENC}==".myth.**backup", TAG+="systemd",
> ENV{SYSTEMD_WANTS}="ext-usb-**backup.service"
>
> (With TAG+ENV approach udev behaves like line with TAG+ENV is
> non-existing: no any error nor any sign it is parsed)
>
> Where the issue is ?
>
> Thx in advance !
>
Hi
I don't really have an idea, but here are some things you could check
additionally:
Does systemd create a .device unit? And if yes is it active/plugged? And
does it have the correct "Wants=ext-usb-backup.service" attribute? Does
udevadm info --query=property --path=<path to sysfs device> show the
correct values for
SYSTEMD_WANTS and TAGS?
Mirco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20121118/bd2c057b/attachment-0001.html>
More information about the systemd-devel
mailing list