-1

The following is my rules file in /etc/udev/rules.d/10-autodvd.rules

SUBSYSTEM=="block", KERNEL=="sr0", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr0"
SUBSYSTEM=="block", KERNEL=="sr1", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr1"
SUBSYSTEM=="block", KERNEL=="sr2", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr2"
SUBSYSTEM=="block", KERNEL=="sr3", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr3"
SUBSYSTEM=="block", KERNEL=="sr4", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh sr4"

It seems to be really hit or miss on actually running the scripts, is there a better way to do this?

whoopn
  • 91
  • 1
  • 2
  • 7

1 Answers1

1

Udev sorts the rules files lexically, and at the time your rules are applied, the ID_CDROM_MEDIA_DVD variable probably isn't set yet. This is the case on a default install of systemd udev. The ID_CDROM* variables are set in 60-cdrom_id.rules, so you should rename your rules file to sort after this.

Note that you're not supposed to start a long running program with the RUN+= key.

   RUN{type}
   [...]
       This can only be used for very short-running
       foreground tasks. Running an event process for
       a long period of time may block all further
       events for this or a dependent device.

       Starting daemons or other long-running
       processes is not appropriate for udev; the
       forked processes, detached or not, will be
       unconditionally killed after the event handling
       has finished.

Your rules may be written as one rule:

SUBSYSTEM=="block", KERNEL=="sr[0-4]", ENV{ID_CDROM_MEDIA_DVD}=="1", ACTION=="change", RUN+="/usr/local/bin/makemkv.sh %k"
Tom Bjerck
  • 246
  • 3
  • 4