8000 Usb printers power off and avahi-deamon · Issue #35 · SickHub/docker-cups-airprint · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Usb printers power off and avahi-deamon #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xavier7179 opened this issue Oct 10, 2021 · 25 comments
Closed

Usb printers power off and avahi-deamon #35

xavier7179 opened this issue Oct 10, 2021 · 25 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@xavier7179
Copy link

I'm using the docker with happiness until I turn off the USB printer (a Canon MP240 if useful) but not the server. Then I still spend hours trying to make it work (putting the printer properly on the network again).

I noticed that in logs if I restart the server, I find the following error:

Unable to communicate with avahi-daemon: Access denied

Am I doing something wrong? Should it be fine to power off the printer while the server is still running?

@DrPsychick
Copy link
Collaborator

The message you mentioned appears from time to time. Does it work when you restart the container (after turning on the printer)?

From time to time I too have issues with the docker container, but after I restart it, it usually works again.

Sorry that I don't have a solution for you. The inner workings of cups (and why it would "forget" the printer when it's off) is a mystery to me.

@xavier7179
Copy link
Author

I did some extra work and investigation. Actually, if I only restart the container, it's not enough. I need to remove the printer on the docker-compose service environment variables, the start it again and add the printer again. This makes the printer available everywhere

@DrPsychick
Copy link
Collaborator

That seems strange. If you've configured the printer through environment variables it should be added/setup with every start of the container.

Can you maybe share your environment variables that you're using to setup the printer?

@xavier7179
Copy link
Author

Sure. I can share my docker-compose configuration:

cups-server:
      container_name: cups-server
      image: drpsychick/airprint-bridge
      restart: unless-stopped
      hostname: cups.home
      networks:
        localnet:
          ipv4_address: $CUPSSERVER_LOCALNET_IP
      security_opt:
         - no-new-privileges:true
      ports:
         - "137:137/udp"
         - "139:139/tcp"
         - "445:445/tcp"
         - "631:631/tcp"
         - "5353:5353/udp"
      environment:
         TZ: $TZ
         CUPS_ADMIN_USER: $CUPS_USERNAME
         CUPS_ADMIN_PASSWORD: $CUPS_PASSWORD
         CUPS_REMOTE_ADMIN: "yes"
         CUPS_WEBINTERFACE: "yes"
         CUPS_SHARE_PRINTERS: "yes"
         CUPS_ACCESS_LOGLEVEL: "access"
         CUPS_LOGLEVEL: "debug"
         CUPS_LPADMIN_PRINTER1: "lpadmin -p Canon-MP240 -D 'Canon MP240' -m 'gutenprint.5.3://bjc-MP240-series/expert'"
         CUPS_LPADMIN_PRINTER1_ENABLE: "cupsenable Canon-MP240"
         CUPS_LPADMIN_PRINTER1_ACCEPT: "cupsaccept Canon-MP240"
      volumes:
         - /var/run/dbus:/var/run/dbus
      devices:
         - /dev/bus:/dev/bus
         #- /dev/usb:/dev/usb   #NOT sure about that...
      labels:
         - "traefik.enable=false"

@DrPsychick
Copy link
Collaborator

Hmm, this lgtm. The lpadmin command should be executed and you should see with every start of the container something like this in the logs:

... POST /admin/ HTTP/1.1" 200 185563 CUPS-Add-Modify-Printer successful-ok

Then at least the printer should be configured in CUPS (not necessarily in Avahi yet).

From your initial post: I just double checked the permission denied message of Avahi and I was mistaken - I don't see that in my logs so maybe this is causing issues, but if so, it should only prevent the printer from appearing for AirPrint. I am running the docker container "privileged", so that might also be worth a try if that solves the issue.

As I personally don't use docker-compose, maybe you want to try if it works with pure docker. If so, then likely docker-compose does sth. differently which causes the issue.

@xavier7179
Copy link
Author

I see those messages too. I checked again and I noticed that if I run the docker and the printer is off, then the CUPS server displays the connection as Connection: file:///dev/null. It looks like that, when the printer is off, something interferes with the connection. Could it be related to the fact that the container has no permanent storage thus something mess with the configuration data?

@DrPsychick
Copy link
Collaborator

So, the missing permanent storage should not be the issue because as long as the container is running the data is there. Whereas when the container is starting while the printer is off - it makes sense that it won't work.

I probably would do the following:

  1. run the container with the printer on -> check if everything's fine
  2. turn off the printer -> check what happens to the connection
  3. turn on the printer again -> check the connection again
  4. try some console commands (or through web interface) to re-enable the printer, like lpinfo -v; lpstat -t; cupsdisable <printername>; cups enable <printername>

I do have an USB printer, but so far I haven't hooked it directly to the container. As I don't know if I will find time to play with that setup, I can offer to do a debug session together: DrPsychick -AT- drsick.net - I can invite you to my slack to chat or we can meet to share screens.

@DrPsychick DrPsychick added bug Something isn't working documentation Improvements or additions to documentation help wanted Extra attention is needed labels Oct 17, 2021
@xavier7179
Copy link
Author

Sorry, it took me a while to be able to check all your steps. Also, I apologize for the long post, but I'm trying to help myself but also other users.

I tried all steps (1 to 4) those are the behaviors:

  1. everything looks fine but it only works the first time I add the printer (see point 3) but I cannot add the printer using IP address, only by AirPrint
  2. no connection changes, the USB path is still there.
  3. nothing changes on the configuration but now the printer is not reachable anymore ("Waiting for printer to become available"), and I get messages like the following ones on the console (IPs are reduced)
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Printing jobs", busy="Printing jobs"
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Active clients and printing jobs", busy="Printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 456] Server address is "192.168.X.XXX".
D [17/Oct/2021:19:44:56 +0200] [Client 456] Accepted from 192.168.X.XXX:52563 (IPv4)
D [17/Oct/2021:19:44:56 +0200] [Client 456] Waiting for request.
D [17/Oct/2021:19:44:56 +0200] [Client 456] POST /printers/Canon-MP240 HTTP/1.1
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Active clients and printing jobs", busy="Active clients and printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 456] Read: status=200, state=6
D [17/Oct/2021:19:44:56 +0200] [Client 456] No authentication data provided.
D [17/Oct/2021:19:44:56 +0200] [Client 456] 2.0 Get-Job-Attributes 34
D [17/Oct/2021:19:44:56 +0200] Get-Job-Attributes ipp://cups.local.:631/printers/Canon-MP240
D [17/Oct/2021:19:44:56 +0200] [Client 456] Returning IPP successful-ok for Get-Job-Attributes (ipp://cups.local.:631/printers/Canon-MP240) from 192.168.1.21.
D [17/Oct/2021:19:44:56 +0200] [Client 456] Content-Length: 273
D [17/Oct/2021:19:44:56 +0200] [Client 456] cupsdSendHeader: code=200, type="application/ipp", auth_type=0
D [17/Oct/2021:19:44:56 +0200] [Client 456] con->http=0x5616acc07060
D [17/Oct/2021:19:44:56 +0200] [Client 456] cupsdWriteClient error=0, used=0, state=HTTP_STATE_POST_SEND, data_encoding=HTTP_ENCODING_LENGTH, data_remaining=273, response=0x5616acb95b60(IPP_STATE_DATA), pipe_pid=0, file=-1
D [17/Oct/2021:19:44:56 +0200] [Client 456] Writing IPP response, ipp_state=IPP_STATE_DATA, old wused=0, new wused=0
D [17/Oct/2021:19:44:56 +0200] [Client 456] bytes=0, http_state=0, data_remaining=273
D [17/Oct/2021:19:44:56 +0200] [Client 456] Flushing write buffer.
D [17/Oct/2021:19:44:56 +0200] [Client 456] New state is HTTP_STATE_WAITING
D [17/Oct/2021:19:44:56 +0200] [Client 456] Waiting for request.
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Printing jobs", busy="Active clients and printing jobs"
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Active clients and printing jobs", busy="Printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 457] Server address is "127.0.0.1".
D [17/Oct/2021:19:44:56 +0200] [Client 457] Accepted from localhost:59464 (IPv4)
D [17/Oct/2021:19:44:56 +0200] [Client 457] Waiting for request.
D [17/Oct/2021:19:44:56 +0200] [Client 457] Connection now encrypted.
D [17/Oct/2021:19:44:56 +0200] [Client 457] HEAD /printers/ HTTP/1.1
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Active clients and printing jobs", busy="Active clients and printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 457] Read: status=200, state=4
D [17/Oct/2021:19:44:56 +0200] [Client 457] No authentication data provided.
D [17/Oct/2021:19:44:56 +0200] [Client 457] cupsdSendHeader: code=200, type="text/html", auth_type=0
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Printing jobs", busy="Active clients and printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 457] HTTP_STATE_WAITING Closing for error 32 (Broken pipe)
D [17/Oct/2021:19:44:56 +0200] [Client 457] Closing connection.
D [17/Oct/2021:19:44:56 +0200] cupsdSetBusyState: newbusy="Printing jobs", busy="Printing jobs"
D [17/Oct/2021:19:44:56 +0200] [Client 457] Waiting for socket close.
D [17/Oct/2021:19:44:56 +0200] [Client 457] Closing on EOF.
D [17/Oct/2021:19:44:56 +0200] [Client 457] Closing connection.
  1. tried to go on docker and run all commands to have stats and enable/disable printer but the lpstat already report something is not right:
no system default destination
device for Canon-MP240: usb://Canon/MP240%20series?serial=207073&interface=1
Canon-MP240 accepting requests since Sun Oct 17 19:36:48 2021
printer Canon-MP240 now printing Canon-MP240-2.  enabled since Sun Oct 17 19:36:48 2021
	Waiting for printer to become available.
Canon-MP240-2           unknown          20480   Sun Oct 17 19:36:48 2021

which looks like a double printer for no reason...

Last comment on the permanent storage. My understanding, so far, is that once the printer goes down (or the docker, which might happen), configuration or temporary files are not ok anymore. In fact, some similar logs are also present when the container restart (with the printer still on):

D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Dirty files"
D [17/Oct/2021:19:29:10 +0200] [Client 5] Server address is "127.0.0.1".
D [17/Oct/2021:19:29:10 +0200] [Client 5] Accepted from localhost:59178 (IPv4)
D [17/Oct/2021:19:29:10 +0200] [Client 5] Waiting for request.
D [17/Oct/2021:19:29:10 +0200] cupsdAddCert: Adding certificate for PID 0
D [17/Oct/2021:19:29:10 +0200] [Client 5] Connection now encrypted.
D [17/Oct/2021:19:29:10 +0200] [Client 5] HEAD /printers/ HTTP/1.1
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Active clients and dirty files"
D [17/Oct/2021:19:29:10 +0200] [Client 5] Read: status=200, state=4
D [17/Oct/2021:19:29:10 +0200] [Client 5] No authentication data provided.
D [17/Oct/2021:19:29:10 +0200] [Client 5] cupsdSendHeader: code=200, type="text/html", auth_type=0
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Dirty files", busy="Active clients and dirty files"
D [17/Oct/2021:19:29:10 +0200] [Client 5] HTTP_STATE_
8000
WAITING Closing for error 32 (Broken pipe)
D [17/Oct/2021:19:29:10 +0200] [Client 5] Closing connection.
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Dirty files", busy="Dirty files"
D [17/Oct/2021:19:29:10 +0200] [Client 5] Waiting for socket close.
D [17/Oct/2021:19:29:10 +0200] [Client 5] Closing on EOF.
D [17/Oct/2021:19:29:10 +0200] [Client 5] Closing connection.
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Dirty files", busy="Dirty files"
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Active clients and dirty files", busy="Dirty files"
D [17/Oct/2021:19:29:10 +0200] [Client 6] Server address is "/run/cups/cups.sock".
D [17/Oct/2021:19:29:10 +0200] [Client 6] Accepted from localhost (Domain)
D [17/Oct/2021:19:29:10 +0200] [Client 6] Waiting for request.
D [17/Oct/2021:19:29:10 +0200] [Client 6] HTTP_STATE_WAITING Closing for error 32 (Broken pipe)
D [17/Oct/2021:19:29:10 +0200] [Client 6] Closing connection.
D [17/Oct/2021:19:29:10 +0200] cupsdSetBusyState: newbusy="Dirty files", busy="Active clients and dirty files"

@DrPsychick
Copy link
Collaborator
DrPsychick commented Oct 17, 2021

What intrigued me is the "Dirty files" so I googled a bit and found some interesting posts, see below.

As you seem to have two printers after turning it back on and/or restarting, I would try to delete the printer before adding it:

# the `|| echo` is needed, in case the command fails and would abort the start script
CUPS_LPADMIN_PRINTER0=lpadmin -x Canon-MP240 || echo

This might hopefully also cleanup / remove any "dirty files" of the printer. When you're just restarting the container, the changed files should remain, so the "stuck" state remains as well. So the other option could be to delete and recreate the container, because then there are no leftovers from previous runs and the printer gets added for the first time which seems to have worked.

PS: thank you for all the details Alessandro, I see it the same way that this might help other people, so I thank you also in their name!

@xavier7179
Copy link
Author

Actually, I solved one thing and I'm still struggling with the other one. Regarding the null file, it is mandatory to add the -v option to the lpadmin (in the configuration) to link the printer with the usb://<path> path. This way, if you start the container and the printer is already on, it seems to work (I checked few times, so I hope it was not something else).

Regarding the on and off, I found this post. Unfortunately, I'm still not able to make it work because the udev folder is cleaned when the docker goes down...

@DrPsychick
Copy link
Collaborator

Does it work, when you add those udev rules mentioned in the post? You could mount them from the host for testing so that they survive a restart of the container.

If so, we only need to find a way to make that configurable through ENV, so that it may work for others as well.

@xavier7179
Copy link
Author

I guess I solved the mystery. Basically, I noticed that despite any attempt the /dev/bus/ folder was not updated, despite being in the device section of the container. Then, I got the inspiration from this post and I moved everything out of device and into volumes (now mapping directly the only part of the bus that I needed /dev/bus/usb:/dev/bus/usb. Tried couple of time and looks like it is working.

Also based on my previous comment, I also attached in the volumes section the /etc/udev:/etc/udev with the rules I was writing about.

@master-ang
Copy link

I also encountered a similar problem. Whenever I turned off the printer and turned it on again, I was prompted to Waiting for printer to become available when printing.I need to restart docker. Is there any solution?

@xavier7179
Copy link
Author

@master-ang did you try what I suggested before?
The solution looks fine, but it is still not the final one: after a while, without tracking the issue down, despite the USB printer correctly recognized inside the container, it stops working, and the only viable solution is to restart the container. I hope someone can jump in and suggest some adjustments.

@master-ang
Copy link
master-ang commented Jan 2, 2022

@xavier7179

/dev/bus/usb:/dev/bus/usb is working. Now I can restart the printer without restarting the container. Thank you~

I hope that @DrPsychick will improve in the next version.

@DrPsychick
Copy link
Collaborator

As this depends on the users setup, the only thing I did now was mentioning it in the Readme (linking to this thread). Any user can mount volumes into the existing container to make USB printers work nicely, so I don't see the need to adjust the image itself.

@master-ang
Copy link

but in QNAP ContainerStation it's not a option. I can't mount root volumes in the GUI. So, either I use the command line method, or I create a symbolic link to solve this indirectly.I hope this mount can be built into the image, so that it can be a lot more convenient.

@DrPsychick
Copy link
Collaborator

I understand. However, the image is a docker image. Any integration with QNAP (which I'm using myself) or other specific integrations is not part of the image and never will be.

I use my ansible role https://github.com/DrPsychick/ansible-docker to "deploy" the docker container to my QNAP. That makes it quite easy to maintain and I only use the UI rarely.

FYI: my vars/cups.yaml looks like this (there you could simply add your --volume to the create_parameters:

containers:
  cups:
    hosts: ["neb"]
    name: "cups"
    basedir: "/share/VMs/docker"
    directory: "cups"
    owner: "admin"
    group: "administrators"
    image: "drpsychick/airprint-bridge"
    version: "latest"
    pull: yes
    create: yes
    restart: yes
    cleanup: yes
    templates:
      cupsenv: { name: "cups.env", mode: "0644" }
    # reuses network of dnsmasq-zion-neb!
    pre_command: "if [ -z \"$(docker network ls | grep qnet-static-bond0-dnsmasq)\" ]; then docker network create --driver=qnet --ipam-driver=qnet --ipam-opt=iface=bond0 --subnet 192.168.1.0/24 --gateway 192.168.1.1 qnet-static-bond0-dnsmasq; fi"
    create_parameters: "--network qnet-static-bond0-dnsmasq --ip 192.168.1.201 --dns 192.168.1.254 --hostname cups.zion --env-file cups.env --privileged --memory 200m -p 137:137/udp -p 139:139/tcp -p 445:445/tcp -p 631:631/tcp -p 5353:5353/udp"
    restart_policy: "always"
    ip: 192.168.1.201

@xavier7179
Copy link
Author

@xavier7179

/dev/bus/usb:/dev/bus/usb is working. Now I can restart the printer without restarting the container. Thank you~

I hope that @DrPsychick will improve in the next version.

Please let us know if it keeps working. As I was saying, the AirPrint part is still not stable on my side, and it does not pick the printer all the time.

@master-ang
Copy link

It keeps working , I often turn off the printer for days, and when I turn it on again it airprints fine.

@xavier7179
Copy link
Author

Just to check it, is it your configuration in the docker-compose like this:

 cups:
      container_name: cups
      image: drpsychick/airprint-bridge
      restart: unless-stopped
      hostname: cups.home
      privileged: true
      networks:
        localnet:
          ipv4_address: $CUPSSERVER_LOCALNET_IP
          #security_opt:
          #  - no-new-privileges:true
      ports:
         - "137:137/udp"
         - "139:139/tcp"
             - "445:445/tcp"
         - "631:631/tcp"
         - "5353:5353/udp"
      environment:
         TZ: $TZ
         CUPS_ADMIN_USER: $CUPS_USERNAME
         CUPS_ADMIN_PASSWORD: $CUPS_PASSWORD
         CUPS_REMOTE_ADMIN: "yes"
         CUPS_WEBINTERFACE: "yes"
         CUPS_SHARE_PRINTERS: "yes"
         CUPS_ACCESS_LOGLEVEL: "access"
         CUPS_LOGLEVEL: "debug"
         CUPS_LPADMIN_PRINTER1: "lpadmin -p <printer_model> -D '<printer_name>' -m '<printer_driver>' -v 'usb://<interface_path>'"
         CUPS_LPADMIN_PRINTER1_ENABLE: "cupsenable <printer_name>"
         CUPS_LPADMIN_PRINTER1_ACCEPT: "cupsaccept <printer_name>"
      volumes:
         - $DOCKERDIR/cups/config:/etc/cups
         - $DOCKERDIR/cups/services:/etc/avahi/services
         - /var/run/dbus:/var/run/dbus
         - /dev/bus/usb:/dev/bus/usb
         - /etc/udev:/etc/udev

@master-ang
Copy link

i just mount dev/bus/usb
no /dbus or /udev

@DrPsychick
Copy link
Collaborator

FYI as it might also help with this issue: I just merged #40 which ensures avahi is always running.

@DrPsychick
Copy link
Collaborator

closing this: it's documented in the readme and has proven to work.

If you disagree, feel free to reopen or open another issue.

@master-ang
Copy link

I have some good news to share: the issue has been resolved!
The solution was quite unexpected. It's possible that I misled you earlier.

Do you remember when I mentioned that I couldn't add my USB printer? I looked up some information online and found out that it was because I hadn't mapped the /dev/usb folder in the system.
Previously, I only mapped /dev/bus/usb and it worked, as I mentioned in my previous feedback

But suddenly, mapping only /dev/bus couldn't find the printer anymore (it used to work perfectly before).
When I created the Docker again, I mapped both /dev/usb and /dev/bus, and not only could I find the printer, but iOS devices could also print duplex normally!!

Additionally, I used your latest version “latest-20250124”, and duplex printing worked fine, so the issue wasn't with your software but with my configuration. I deeply apologize for wasting your precious time. However, it was through our joint testing, repeatedly deleting and creating docker, that I discovered the unmapped issue. Otherwise, since printing was working normally, I probably wouldn't have thought it was due to the unmapped folder.

I think you can cancel the duplex version because the original version is also OK.

Thank you again! And Happy New Year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants
0