SickHub / docker-cups-airprint

A standalone CUPS and Avahi (mDNS/Bonjour) server, exposing local printers on AirPrint for iOS devices
GNU General Public License v3.0
160 stars 38 forks source link

Work on homeassistant: portainer #69

Open GhostR111der opened 1 year ago

GhostR111der commented 1 year ago

Hello, I have a Rapsberry 3B and have a homeassistant OS installed on it with Portainer installed inside to run docker containers. I have successfully used the previous version of your product and have been printing to the printer via airprint. But after the last container update, I can no longer access the CUPS address. Can you help?

DrPsychick commented 1 year ago

I can sure try to help ;)

The last significant update on this repo would have been this: https://github.com/SickHub/docker-cups-airprint/commit/6162efca48d4693c2abfe1c37cfbb25defe7df57

All other changes come from the base ubuntu image or the CUPS version itself and I have no control over that.

Can you elaborate more on what the issue is? Is the service in the container not listening on the port you expect it to listen?

GhostR111der commented 1 year ago

Hello! Sorry for so long answer. Trying to figure out what the problem is. This is log from container (Portainer):

avahi-daemon 0.8 starting up.
Successfully called chroot().
Successfully dropped remaining capabilities.
No service file found in /etc/avahi/services.
Joining mDNS multicast group on interface eth0.IPv4 with address 172.30.232.3.
New relevant interface eth0.IPv4 for mDNS.
Joining mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
New relevant interface lo.IPv4 for mDNS.
Network interface enumeration completed.
Registering new address record for 172.30.232.3 on eth0.IPv4.
Registering new address record for 127.0.0.1 on lo.IPv4.
Server startup complete. Host name is 1e53c79b2cb5.local. Local service cookie is 932020102.
X [11/Aug/2023:14:02:30 +0000] cupsdDoSelect() failed - Bad address!
X [11/Aug/2023:14:02:30 +0000] Listeners[0] = 4
X [11/Aug/2023:14:02:30 +0000] Listeners[1] = 5
X [11/Aug/2023:14:02:30 +0000] Listeners[2] = 6
X [11/Aug/2023:14:02:30 +0000] CGIPipes[0] = 7
E [11/Aug/2023:14:02:30 +0000] Scheduler shutting down due to program error.
.Setting up watches.
Watches established.
Process 30 died: No such process; trying to remove PID file. (/run/avahi-daemon//pid)
Found user 'avahi' (UID 105) and group 'avahi' (GID 112).
Successfully dropped root privileges.
avahi-daemon 0.8 starting up.
Successfully called chroot().
Successfully dropped remaining capabilities.
No service file found in /etc/avahi/services.
Joining mDNS multicast group on interface eth0.IPv4 with address 172.30.232.3.
New relevant interface eth0.IPv4 for mDNS.
Joining mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
New relevant interface lo.IPv4 for mDNS.
Network interface enumeration completed.
Registering new address record for 172.30.232.3 on eth0.IPv4.
Registering new address record for 127.0.0.1 on lo.IPv4.
Server startup complete. Host name is 1e53c79b2cb5.local. Local service cookie is 2223828344.
X [11/Aug/2023:14:02:46 +0000] cupsdDoSelect() failed - Bad address!
X [11/Aug/2023:14:02:46 +0000] Listeners[0] = 4
X [11/Aug/2023:14:02:46 +0000] Listeners[1] = 5
X [11/Aug/2023:14:02:46 +0000] Listeners[2] = 6
X [11/Aug/2023:14:02:46 +0000] CGIPipes[0] = 7
E [11/Aug/2023:14:02:46 +0000] Scheduler shutting down due to program error.

I googled what the error was and found this answer on one forum: [https://stackoverflow.com/questions/74949586/cannot-start-cups-service-in-docker-container-cups-socket-is-missing] It says: "This seems to be an issue with Docker 23.x setting the NOFILE limit to unlimited which cups cannot handle."

To be honest I have absolutely no idea how I can change the value of LimitNOFILE=, since I am using your container inside Home Assistant OS (Portainer). Is there any way to change the container itself to make it work?

DrPsychick commented 1 year ago

When I run ulimit in the container on a Ubuntu system I see the following, so the number of open files seems limited to 1048576. Are you sure it's related to the ulimit? Maybe cups does not like the .local hostname?

docker run --rm -it --entrypoint /bin/bash drpsychick/airprint-bridge
root@54337de90c07:/# ulimit -a
real-time non-blocking time  (microseconds, -R) unlimited
core file size              (blocks, -c) unlimited
data seg size               (kbytes, -d) unlimited
scheduling priority                 (-e) 0
file size                   (blocks, -f) unlimited
pending signals                     (-i) 128038
max locked memory           (kbytes, -l) 64
max memory size             (kbytes, -m) unlimited
open files                          (-n) 1048576
pipe size                (512 bytes, -p) 8
POSIX message queues         (bytes, -q) 819200
real-time priority                  (-r) 0
stack size                  (kbytes, -s) 8192
cpu time                   (seconds, -t) unlimited
max user processes                  (-u) unlimited
virtual memory              (kbytes, -v) unlimited
file locks                          (-x) unlimited
GhostR111der commented 1 year ago

How I am catastrophically lacking in knowledge. I do everything by trial and error. I've tried changing the network settings in the container to everything I can think of, but since I don't know what I'm doing, I can't get the container to work. I have also tried other CUPS container alternatives, all of them fail to start. Yours worked perfectly, AirPrint worked, the drivers for my printer were just inside your container, but after updating Portainer everything stopped working. I got hooked on ulimit because it's probably the only solution I could find on the internet.

mundschenk-at commented 1 year ago

I assume @GhostR111der is using HAOS 10.x, there the docker ulimit for the number of file handles changed to unlimited. This has been an issue with several HA add-ons (basically docker containers with some extra scaffolding). See https://github.com/hassio-addons/addon-emqx/pull/38 for an example.

GhostR111der commented 1 year ago

I assume @GhostR111der is using HAOS 10.x, there the docker ulimit for the number of file handles changed to unlimited. This has been an issue with several HA add-ons (basically docker containers with some extra scaffolding).

Yes, you're absolutely right

DrPsychick commented 1 year ago

@GhostR111der did this solve your issue? Then we can close this issue.

GhostR111der commented 1 year ago

@DrPsychick no, unfortunately no, the problem is not solved. What @mundschenk-at wrote is not a solution, it's more of a statement of fact. I could not find a solution to the problem.

mundschenk-at commented 1 year ago

@GhostR111der If you are using docker-compose, you can set the ulimits like this. Not sure how to do that from the Portainer UI, though (and I've never used the Portainer add-on in HAOS).