[systemd-devel] systemd195: issue with udev launched script

Colin Guthrie gmane at colin.guthr.ie
Sun Nov 18 08:54:40 PST 2012


'Twas brillig, and Warpme at 16/11/12 16:37 did gyre and gimble:
> On 11/15/12 9:05 PM, Kay Sievers wrote:
>> You can use systemd to instantiate a service on device discovery (or
>> run a daemon that listens to events from udev on old init systems).
>> Check how bluetooth, cups printers, usbmux, ... is handled:
>> TAG+="systemd",
>> ENV{SYSTEMD_WANTS}="configure-printer at usb-$env{BUSNUM}-$env{DEVNUM}.service"
>> TAG+="systemd", ENV{SYSTEMD_WANTS}+="bluetooth.target" TAG+="systemd",
>> ENV{SYSTEMD_WANTS}="usbmuxd.service" Kay 
> Well,
> Things pretend to be simple seems to be not simple
> After few hours of fighting with issue I have to ask for help.
> 
> 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"


Just as a general observation, I don't think you even need to delve into
udev rules to make all this work as systemd handles device mounts
internally.


You can simply create a .mount unit for your drive such that when it is
inserted it is mounted automatically (you may have to BindTo= and After=
the corresponding .device unit for the external drive IIUC).

Then, simply adjust your ext-usb-backup.service to
BindTo=your-mount-unit.mount and After=your-mount-unit.mount

This means that whenever the mount unit is started (i.e. when ever it's
mounted), your service is started immediately after mount.


Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/



More information about the systemd-devel mailing list