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

Warpme warpme at o2.pl
Sun Nov 18 05:46:32 PST 2012


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 !




log for ENV{ID_FS_LABEL_ENC}==".myth.backup", RUN+="/usr/bin/systemctl
start ext-usb-backup.service"

Nov 16 16:00:31  LINK 'usbhd-sdc1' /etc/udev/rules.d/98-usbhd.rules:50
Nov 16 16:00:31  IMPORT '/sbin/blkid -o udev -p /dev/sdc1'
/etc/udev/rules.d/98-usbhd.rules:52
Nov 16 16:00:31  starting '/sbin/blkid -o udev -p /dev/sdc1'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_LABEL=.myth.backup'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_LABEL_ENC=.myth.backup'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_UUID=fd3104ea-d5c0-4a8f-beba-8ab69115b192'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_UUID_ENC=fd3104ea-d5c0-4a8f-beba-8ab69115b192'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_SEC_TYPE=ext2'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_VERSION=1.0'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out) 'ID_FS_TYPE=ext3'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_USAGE=filesystem'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_SCHEME=dos'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_TYPE=0x83'
Nov 16 16:00:31  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_NUMBER=1'
Nov 16 16:00:31  starting '/bin/mkdir -p /media/.myth.backup'
Nov 16 16:00:31  '/bin/mkdir -p /media/.myth.backup' [16538] exit with
return code 0
Nov 16 16:00:31  starting '/bin/mount -t auto -o rw,noauto,noatime
/dev/sdc1 /media/.myth.backup'
Nov 16 16:00:31  '/bin/mount -t auto -o rw,noauto,noatime /dev/sdc1
/media/.myth.backup' [16539] exit with return code 0
Nov 16 16:00:31  starting '/usr/bin/systemctl start ext-usb-backup.service'
Nov 16 16:00:31  Starting MythtTV ExtUSB Backup Helper...
Nov 16 16:00:34  validate module index
Nov 16 16:00:37  validate module index
Nov 16 16:00:40  validate module index
Nov 16 16:00:43  validate module index
Nov 16 16:00:46  validate module index
Nov 16 16:00:49  validate module index
Nov 16 16:00:52  validate module index
Nov 16 16:00:55  validate module index
Nov 16 16:00:58  validate module index
Nov 16 16:01:01  worker [16535]
/devices/pci0000:00/0000:00:09.0/0000:04:00.0/usb3/3-1/3-1:1.0/host12/target12:0:0/12:0:0:0/block/sdc/sdc1
timeout; kill it
Nov 16 16:01:01  seq 1826
'/devices/pci0000:00/0000:00:09.0/0000:04:00.0/usb3/3-1/3-1:1.0/host12/target12:0:0/12:0:0:0/block/sdc/sdc1'
killed
Nov 16 16:01:01  seq 1826 done with -64
Nov 16 16:01:01  validate module index
Nov 16 16:01:01  worker [16535] exit
Nov 16 16:01:01  worker [16535] terminated by signal 9 (Killed)
Nov 16 16:01:01  worker [16535] cleaned up
Nov 16 16:01:18  Started MythtTV ExtUSB Backup Helper.



Log for ENV{ID_FS_LABEL_ENC}==".myth.backup", TAG+="systemd",
ENV{SYSTEMD_WANTS}="ext-usb-backup.service"

Nov 16 15:57:34  IMPORT '/sbin/blkid -o udev -p /dev/sdc1'
/etc/udev/rules.d/98-usbhd.rules:52
Nov 16 15:57:34  starting '/sbin/blkid -o udev -p /dev/sdc1'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_LABEL=.myth.backup'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_LABEL_ENC=.myth.backup'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_UUID=fd3104ea-d5c0-4a8f-beba-8ab69115b192'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_UUID_ENC=fd3104ea-d5c0-4a8f-beba-8ab69115b192'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_SEC_TYPE=ext2'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_VERSION=1.0'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out) 'ID_FS_TYPE=ext3'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_FS_USAGE=filesystem'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_SCHEME=dos'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_TYPE=0x83'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_NUMBER=1'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_OFFSET=63'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_SIZE=1953520002'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1'(out)
'ID_PART_ENTRY_DISK=8:32'
Nov 16 15:57:34  '/sbin/blkid -o udev -p /dev/sdc1' [16203] exit with
return code 0
Nov 16 15:57:34  starting '/bin/mkdir -p /media/.myth.backup'
Nov 16 15:57:34  '/bin/mkdir -p /media/.myth.backup' [16204] exit with
return code 0
Nov 16 15:57:34  starting '/bin/mount -t auto -o rw,noauto,noatime
/dev/sdc1 /media/.myth.backup'
Nov 16 15:57:34  '/bin/mount -t auto -o rw,noauto,noatime /dev/sdc1
/media/.myth.backup' [16205] exit with return code 0
Nov 16 15:57:34  adding watch on '/dev/sdc1'
Nov 16 15:57:34  created db file '/run/udev/data/b8:33' for
'/devices/pci0000:00/0000:00:09.0/0000:04:00.0/usb3/3-1/3-1:1.0/host12/target12:0:0/12:0:0:0/block/sdc/sdc1'
Nov 16 15:57:34  passed -1 bytes to netlink monitor 0xd885b0
Nov 16 15:57:34  seq 1825 processed with 0
Nov 16 15:57:34  seq 1825 done with 0
Nov 16 15:57:37  cleanup idle workers
Nov 16 15:57:37  validate module index
Nov 16 15:57:37  unload module index
Nov 16 15:57:37  worker [16200] exit
Nov 16 15:57:37  worker [16200] cleaned up


-------------- next part --------------
A non-text attachment was scrubbed...
Name: warpme.vcf
Type: text/x-vcard
Size: 83 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20121118/928e2ebd/attachment.vcf>


More information about the systemd-devel mailing list