Starting makemkvcon through udev rule - strange behaviour

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

Starting makemkvcon through udev rule - strange behaviour

Post by ChristianMate »

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 (ripdisc.sh) 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 (run_on_disc_inserted.sh) which is called by udev and simply starts my ripping script in this way:

Code: Select all

/bin/bash sudo -u myusername /pathtoscript/ripdisc.sh & exit
. This also starts up ripdisc.sh 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 run_on_disc_inserted.sh every minute. My ripdisc.sh 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!
beandog
Posts: 36
Joined: Sun Feb 18, 2018 7:42 am
Location: /usa/utah
Contact:

Re: Starting makemkvcon through udev rule - strange behaviour

Post by beandog »

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 (run_on_disc_inserted.sh) 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.

/etc/udev/rules.d/70-persistent-cd.rules:

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: DEVTYPE=disk
E: GENERATED=1
E: ID_ATA=1
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_BUS=ata
E: ID_CDROM=1
E: ID_CDROM_BD=1
E: ID_CDROM_CD=1
E: ID_CDROM_DVD=1
E: ID_CDROM_MRW=1
E: ID_CDROM_MRW_W=1
E: ID_MODEL=ATAPI_iHOS104
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_REVISION=WL0D
E: ID_SERIAL=ATAPI_iHOS104_3775504067_206017500
E: ID_SERIAL_SHORT=3775504067_206017500
E: ID_TYPE=cd
E: MAJOR=11
E: MINOR=0
E: SUBSYSTEM=block
E: SYSTEMD_MOUNT_DEVICE_BOUND=1
E: SYSTEMD_READY=0
E: TAGS=:seat:udev-acl:
E: USEC_INITIALIZED=7302213
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.

/usr/local/bin/onevent.trayclose

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 - https://dvds.beandog.org/doku.php?id=udev
ember1205
Posts: 63
Joined: Fri May 05, 2017 3:19 pm

Re: Starting makemkvcon through udev rule - strange behaviour

Post by ember1205 »

If you want to reverse-engineer a working solution, here's the one that I used to get this stuff up and running. https://b3n.org/automatic-ripping-machine/

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