After some more research, I found an alternative solution for this issue in 
Jessie

Pros:
- no changes to usbmount code necessary, no upstream dependency
- can easily be added as a fix on existing usbmount installs
- works not only for NTFS mounts, but also for long running scripts hooked by 
usbmount (via mount.d & umount.d folders)
- should be easy to be integrated into the Debian package

Cons:
- requires systemd! Since to problem is caused by systemd logic only, this 
should not be a big issue. If the maintainer would integrate the solution into 
the package, this needs different install time handling for systemd is NOT 
installed on the system.

The solution is based on the following two additional files:


/etc/udev/rules.d/usbmount.rules
# Rules for USBmount -*- conf -*-
KERNEL=="sd*", DRIVERS=="sbp2",         ACTION=="add",  
PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", 
ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*", SUBSYSTEMS=="usb",       ACTION=="add",  
PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", 
ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="ub*", SUBSYSTEMS=="usb",       ACTION=="add",  
PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", 
ENV{SYSTEMD_WANTS}+="%c"
KERNEL=="sd*",                          ACTION=="remove",       
RUN+="/usr/share/usbmount/usbmount remove"
KERNEL=="ub*",                          ACTION=="remove",       
RUN+="/usr/share/usbmount/usbmount remove"


/etc/systemd/system/usbmount@.service
[Unit]
BindTo=%i.device
After=%i.device

[Service]
Type=oneshot
TimeoutStartSec=0
Environment=DEVNAME=%I
ExecStart=/usr/share/usbmount/usbmount add
RemainAfterExit=yes


How it works:
Starting usbmount via systemd-escape ensues, that a different cgroup than the 
one from the udev environment is used. Therefore, sub processes started from 
usbmount are not killed when udev terminates its cgroup.
The original udev rules file /lib/udev/rules.d/usbmount.rules from the package 
can remain unchanged, as /etc/udev/rules.d/usbmount.rules overrules it.

Valuable source of further information are
http://blog.fraggod.net/2015/01/12/starting-systemd-service-instance-for-device-from-udev.html
http://unix.stackexchange.com/questions/28548/how-to-run-custom-scripts-upon-usb-device-plug-in/28711#28711

Reply via email to