(Solved) Getting custom udev rule to work?


Recommended Posts

Hiya. Long story short my printer seems to have some fault and it randomly reconnects (disconnects and connects again) every 30 minutes.

 

Bus 001 Device 005: ID 03f0:1d17 Hewlett-Packard LaserJet 1320

 

So I made this udev rule 

 

SUBSYSTEM=="usb", ACTION=="add",  ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="1d17", SYMLINK+="hpusbprinter"

 

However it doesn't seem to work. I also tried adding the group "lp", but that was to no avail either.

 

Problem is every time it reconnects my device number goes up, so after 3 days I'd have like device number 87, and also I'm passing the /dev/bus/usb/XXX/XXX to my CUPS docker container, which stops working as soon as the bus device changes.

 

Do you people have any ideas how to get this going?

Edited by Arandomdood
Link to comment

 

Update & Solution; after trying many things, reading up on udev and drivers I found the answer:

 

I created an udev rule with:

nano /etc/udev/rules.d/99-usb-printer.rules

 

In the file is written:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="03f0", ATTRS{idProduct}=="1d17", ATTR{serial}=="yourSerialNumb", SYMLINK+="hpusbprinter"

 

(yourSerialNumb,idVendor and idProduct can be found in lsusb and then lsusb -d device_vendor:device_productID (you'll see what I mean as soon as you run lsmod alone)

 

Then I reloaded and triggered:

 

udevadm control --reload-rules
udevadm trigger

 

And voila! It was working.

 

You can also use the followingg command to aid you with debugging:

 

udevadm info -q path -n /dev/bus/XXX/XXX/XXX #This is to find the device
udevadm monitor --property #This is to observe adds, removes, changes, binds and unbinds
udevadm test /devices/XXXXXX/XXXX/XXXXX/XXXX (this refers to the 1st command above in this code that finds the device via info -q path, it will basically look for an udev rule that applies to this device and trigger it alone so you can observe "log" what happens.

 

My last todo and I will edit later with solution is how to make this device get automatically written & added upon system boot since Unraid boots from USB. If we had a persistent OS you wouldn't need to do this (if you're on Debian or whatever), but since we run live from ram that's not the case.

 

 

Then since this is all for a CUPS container in my case, I added the ydkn/cups from @José Coelho - maintained here 

and I removed the Printer argument, and added an extra argument via advanced options within docker in unraid the following argument:

 

--device=$(readlink -f /dev/hpusbprinter)

 

This was needed because you need an absolute path and udev only creates relative ones.

 

 

------------------

 

WHY DO THIS? WHAT'S MY REASON?

 

My printer has some flaw that it reconnects usb every 30 mintues, so this way I am keeping it symlinked to a specific /dev/ non stop so that I don't have to reset my container. So far it seems to work. Hopefully the rising bus number won't pose to be a problem someday.

 

EDIT2: Yeah.. this wasn't worth doing. Udev rule worked but it this only works for devices that read directly from /dev/. CUPS container that I was using requires actual device to initialize within the container so yeah..

Edited by Arandomdood
Link to comment
  • Arandomdood changed the title to (Solved) Getting custom udev rule to work?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.