Starting makemkvcon through udev rule - strange behaviour

The place to discuss linux version of MakeMKV
Post Reply
Posts: 1
Joined: Tue Feb 21, 2017 10:00 am

Starting makemkvcon through udev rule - strange behaviour

Post by ChristianMate » Tue Feb 21, 2017 10:05 am

Hey guys,

i'm not shure if makemkv or my distribution itself causes the problem but i cant get makemkvcon doing its job when started from udev rule. I'm not a linux wizard and this was my first time setting up a udev rule. ;)

I have a headless Ubuntu Server (16.10) running and first thing i have done was setting up a script ( which rips a disc, moves files into certain directories and does some logging. This runs just fine when started manually from the bash. Doesnt make a difference if started as root or myusername.

Then i set up a udev rule which reacts if a disc is inserted. This also works now and starts my script. All commands inside my scripts are executed but makemkvcon does nothing but drops "Application failed to initialize" or nothing (cant provide u any further information right now since i'm currently not on this maschine). My device (/dev/sr0) is there since blkid is able to grap the discs title..

I invested a bunch of time googling and found that you can't start long living processes from udev. So i set up another ("in-between") script ( which is called by udev and simply starts my ripping script in this way:

Code: Select all

/bin/bash sudo -u myusername /pathtoscript/ & exit
. This also starts up as it is supposed to but the behaviour stays the same.

Then i came up with kind of a hack: My udev rule now is just putting an empty file at a certain position. Like so:

Code: Select all

/usr/bin/touch /pathtofile/disc_inserted
. Nothing else. Additionaly i've set up a a crontab which starts every minute. My script checks if the file /pathtofile/disc_inserted exists and if so deletes it and continues. If the file disc_inserted is not there it just returns.

Well. This solution now works like expected! :-) But:
1. This isnt the nicest approach and
2. I would like to know why my script works fine if called through crontab but not if called through udev?! What is the missing bit i don't see?

I should mention: Initially i installed makemkv from the packages but i had problems with my blu-ray drive and wasn't sure what causes this so i deinstalled the package stuff, downloaded the sources and compiled/installed makemkv by myself. Later i realize that my drive causes the problems and i went for a new one which then worked ootb. After having the first problems with this udev stuff i deinstalled makemkv manually by removing the files by hand and then reinstalled it from the packages. Maybe something went wrong here? How can i find out what files have to be in which places and what files makemkvcon actually needs?

Another thing: If my ripping script is started through crontab makemkvcon tells me some stuff related to auto updates and that i'm in a 30 days testing period. If I start the script manually these messages doesnt appear. Yes, i have settings.conf set up with the current key and the .MakeMKV folder is in myusernames home as well as in the roots home.

Thanks for your time!

Posts: 10
Joined: Sun Feb 18, 2018 7:42 am
Location: /usa/utah

Re: Starting makemkvcon through udev rule - strange behaviour

Post by beandog » Thu Nov 15, 2018 10:13 am

It's an old post I know, but udev is tricky, so here I am. :)
I invested a bunch of time googling and found that you can't start long living processes from udev. So i set up another ("in-between") script ( which is called by udev and simply starts my ripping script in this way:
You can setup a udev rule to trigger an event when your drive tray is closed *and* a disc is present.


Code: Select all

SUBSYSTEM=="block", ENV{ID_MODEL}=="ATAPI_iHOS104", ENV{ID_CDROM_MEDIA_DVD}=="1", ENV{ID_CDROM_MEDIA_STATE}=="complete", RUN+="/usr/local/bin/onevent.trayclose"
You can get the udev environment variables by querying the device using udevadm:

Code: Select all

udevadm info -n /dev/sr0 -q all

Code: Select all

P: /devices/pci0000:00/0000:00:11.0/ata2/host1/target1:0:0/1:0:0:0/block/sr0
N: sr0
L: -100
S: bluray
S: cdrom
S: disk/by-id/ata-ATAPI_iHOS104_3775504067_206017500
S: dvd
E: DEVLINKS=/dev/bluray /dev/cdrom /dev/disk/by-id/ata-ATAPI_iHOS104_3775504067_206017500 /dev/dvd
E: DEVNAME=/dev/sr0
E: DEVPATH=/devices/pci0000:00/0000:00:11.0/ata2/host1/target1:0:0/1:0:0:0/block/sr0
E: ID_BUS=ata
E: ID_MODEL_ENC=ATAPI\x20\x20\x20iHOS104\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_SERIAL=ATAPI_iHOS104_3775504067_206017500
E: ID_SERIAL_SHORT=3775504067_206017500
E: TAGS=:seat:udev-acl:
You're right about udev being a pain firing off scripts, because it has interesting consequences if it doesn't like how long it takes. I run a local command which uses "at" (part of the at daemon, "atd") to immediately send it off. I prefer it that way rather than using nohup, and forking in the background.


Code: Select all

if [[ -z "$ID_FS_LABEL" ]]; then ID_FS_LABEL=$(busybox volname $DEVNAME); fi
echo "/usr/bin/sudo -u steve /home/steve/Videos/Rip-o-Matic/spincycle $DEVNAME $ID_FS_LABEL" | at now
Once you're done setting up udev, you'll have to reload its rules -- it won't just work right away.

Code: Select all

udevadm trigger
Good luck. I documented more of it here -

Posts: 55
Joined: Fri May 05, 2017 3:19 pm

Re: Starting makemkvcon through udev rule - strange behaviour

Post by ember1205 » Thu Nov 29, 2018 10:08 pm

If you want to reverse-engineer a working solution, here's the one that I used to get this stuff up and running.

I actually DID reverse-engineer a fair amount of it and extended the functionality to suit my own needs. I've written a pretty big "management" script that moves content around, calls Filebot for renaming, stages the media files through various areas on disc, and then moves them to library locations so that my Plex server can see and import them into the system. I've also added my own transcoding mechanism that uses the same underlying product as what Ben uses except that I don't do it as part of the rip - I have a much more powerful machine to do it and it takes less time.

Post Reply