[systemd-devel] Starting systemd service in udev rule via ENV{SYSTEMD_WANTS} - help needed

Lennart Poettering lennart at poettering.net
Mon Nov 19 16:31:55 PST 2012


On Sun, 18.11.12 14:46, Warpme (warpme at o2.pl) wrote:

> 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:

A few general issues, have you checked with "udevadm test" and "udevadm
status" that everything gets executed correctly?
> 
> 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"

Usually one would write ENV{SYSTEMD_WANTS}+="..." rather than just =. 
Maybe  that's the issue here?

It's probably better to pull in a mount unit rather than invoking
/bin/mount directly. That's how we do that for fuse and configfs in 
/lib/udev/rules.d/99-systemd.rules

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list