When restarting avahi-daemon cups does not reconnect to it - workaround

Bug #1158686 reported by Till Kamppeter
98
This bug affects 20 people
Affects Status Importance Assigned to Milestone
avahi (Ubuntu)
Fix Released
High
Dimitri John Ledkov

Bug Description

I use CUPS with shared printers and the shared printers are Bonjour-broadcasted by Avahi. This works well when avahi-daemon is started before cups and both keep running. But if I restart (stop and start gain) avahi-daemon while CUPS is running, CUPS does not reconnect to avahi-daemon again and so stops broadcasting. What I expect is that CUPS reconnects after the restart of avahi-daemon. This can easily happen if for example the avahi-daemon package gets updated, avahi-daemon crashes, or the admin changes the configuration of avahi-daemon.

I am using Ubuntu Raring (13.04) with CUPS 1.6.2.

The real fix would need to be done in CUPS and therefore I did the following upstream bug report:

https://www.cups.org/str.php?L4300

For the time being until CUPS gets fixed I suggest the following workaround:

If one adds the following lines to the end of the /etc/init/avahi-daemon.conf file

----------
post-start script
    if lpstat -h localhost -r 2>/dev/null | grep -qv not; then
        killall -HUP cupsd
    fi
end script
----------

the CUPS daemon gets kicked after starting avahi-daemon and so reconnects. The "if" only comes true if "lpstat" is present and the answer of "lpstat -h localhost -r" does not contain "not", meaning that the CUPS daemon is running.

This works at least for restarting the avahi-daemon by "stop avahi-daemon; ...; start avahi-daemon" (what happens when updating avahi-daemon) or by the "respawn" (what happens when avahi-daemon crashes).

It does not work with "restart avahi-daemon". Any addition to my suggested workaround to make this work is welcome.

Can this workaround be applied to Raring? Thanks.

Changed in avahi (Ubuntu):
importance: Undecided → High
milestone: none → ubuntu-13.04
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

post-start script
    if status cups | grep start/running; then
        reload cups;
    fi
end script

See http://upstart.ubuntu.com/cookbook, we want to check for cups that we are managing (not any other) & reload will send to our cups HUP to reload.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Reading cookbook http://upstart.ubuntu.com/cookbook/#restart-a-job-on-a-particular-event
This extra task job should solve both start & restart of avahi-daemon and reload cups appropriately.

$ cat /etc/init/avahi-cups-reload.conf
start on started avahi-daemon
task
exec reload cups

Thus with no changes in the avahi-daemon.conf. Can you test above job to make sure that it does the right thing in your setup both on cold boot, stop & start and restart of avahi?

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

Looks correct sequence of events to me, this is avahi-daemon restart:
1 2013-03-22 10:22:12.696810 stopping JOB='avahi-daemon' INSTANCE='' RESULT='ok'
2 2013-03-22 10:22:12.704692 stopping JOB='cups-browsed' INSTANCE='' RESULT='ok'
3 2013-03-22 10:22:12.705150 starting JOB='cups-browsed' INSTANCE=''
4 2013-03-22 10:22:12.705537 started JOB='cups-browsed' INSTANCE=''
5 2013-03-22 10:22:12.705920 starting JOB='avahi-daemon' INSTANCE=''
6 2013-03-22 10:22:12.706322 stopping JOB='cups-browsed' INSTANCE='' RESULT='ok'
7 2013-03-22 10:22:12.706703 starting JOB='cups-browsed' INSTANCE=''
8 2013-03-22 10:22:12.712707 started JOB='cups-browsed' INSTANCE=''
9 2013-03-22 10:22:12.720260 starting JOB='avahi-cups-reload' INSTANCE=''
10 2013-03-22 10:22:12.720981 started JOB='avahi-cups-reload' INSTANCE=''
11 2013-03-22 10:22:12.721324 stopping JOB='avahi-cups-reload' INSTANCE='' RESULT='ok'
12 2013-03-22 10:22:12.721686 stopped JOB='avahi-cups-reload' INSTANCE='' RESULT='ok'
13 2013-03-22 10:22:12.721892 started JOB='avahi-daemon' INSTANCE=''

And this is stop avahi and start avahi:
1 2013-03-22 10:22:12.696810 stopping JOB='avahi-daemon' INSTANCE='' RESULT='ok'
2 2013-03-22 10:22:12.704692 stopping JOB='cups-browsed' INSTANCE='' RESULT='ok'
3 2013-03-22 10:22:12.705150 starting JOB='cups-browsed' INSTANCE=''
4 2013-03-22 10:22:12.705537 started JOB='cups-browsed' INSTANCE=''
5 2013-03-22 10:22:12.705920 starting JOB='avahi-daemon' INSTANCE=''
6 2013-03-22 10:22:12.706322 stopping JOB='cups-browsed' INSTANCE='' RESULT='ok'
7 2013-03-22 10:22:12.706703 starting JOB='cups-browsed' INSTANCE=''
8 2013-03-22 10:22:12.712707 started JOB='cups-browsed' INSTANCE=''
9 2013-03-22 10:22:12.720260 starting JOB='avahi-cups-reload' INSTANCE=''
10 2013-03-22 10:22:12.720981 started JOB='avahi-cups-reload' INSTANCE=''
11 2013-03-22 10:22:12.721324 stopping JOB='avahi-cups-reload' INSTANCE='' RESULT='ok'
12 2013-03-22 10:22:12.721686 stopped JOB='avahi-cups-reload' INSTANCE='' RESULT='ok'
13 2013-03-22 10:22:12.721892 started JOB='avahi-daemon' INSTANCE=''

Changed in avahi (Ubuntu):
assignee: nobody → Dmitrijs Ledkovs (xnox)
status: New → Triaged
Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

All working correctly with avahi-daemon 0.6.31-1ubuntu3. Thank you very much.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package avahi - 0.6.31-1ubuntu3

---------------
avahi (0.6.31-1ubuntu3) raring; urgency=low

  * Reload cups to refresh remote queues, when avahi-daemon starts. (LP:
    #1158686). Until cups learns to reconnect to avahi by itself
    https://www.cups.org/str.php?L4300 .
 -- Dmitrijs Ledkovs <email address hidden> Fri, 22 Mar 2013 10:49:47 +0000

Changed in avahi (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
Øyvind Stegard (oyvindstegard) wrote :

I see two instances of the reload cups job in /var/log/boot.log, and the second one fails:
 * Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ OK ]
 * Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ fail ]

So the job triggers twice, it seems. Probably doesn't hurt anything, but looks bad. I'm on updated 13.04 (upgraded from 12.10).

Revision history for this message
Mauro (jasmines) wrote :

The bug is not solved for me with avahi - 0.6.31-1ubuntu3

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Mauro, which version of the avahi-daemon package do you have installed? Do you have a /etc/init/avahi-cups-reload.conf file? What does it contain? Can you also attach /var/log/boot.log and /var/log/syslog. Thanks.

Revision history for this message
Mauro (jasmines) wrote :

Requested info are attached.

dpkg -s avahi-daemon
Package: avahi-daemon
Status: install ok installed
Priority: optional
Section: net
Installed-Size: 341
Maintainer: Ubuntu Developers <email address hidden>
Architecture: amd64
Multi-Arch: foreign
Source: avahi
Version: 0.6.31-1ubuntu3
Depends: libavahi-common3 (>= 0.6.16), libavahi-core7 (>= 0.6.24), libc6 (>= 2.14), libcap2 (>= 2.10), libdaemon0 (>= 0.13), libdbus-1-3 (>= 1.1.1), libexpat1 (>= 2.0.1), upstart-job, upstart (>= 0.6.7-4), adduser, dbus (>= 1.2.16-0ubuntu3), lsb-base (>= 3.0-6), bind9-host | host
Recommends: libnss-mdns
Suggests: avahi-autoipd
Conffiles:
 /etc/default/avahi-daemon 292bdbb95b392a71a0c363eb58b3a119
 /etc/network/if-up.d/avahi-daemon 19057755be7963e97943d32a959d5193
 /etc/resolvconf/update-libc.d/avahi-daemon 2cf53ff5a00f9d1fed653a2913de5bc7
 /etc/avahi/hosts 186990ae1edac95a88dbef6a36a07716
 /etc/avahi/avahi-daemon.conf bd8d4eda789abe26c48c1f1f74d19551
 /etc/dbus-1/system.d/avahi-dbus.conf 4b8ff37c10615ae704b7827a438ff534
 /etc/init/avahi-daemon.conf 0303b3961d5ffee8f05805b1dd06f475
 /etc/init/avahi-cups-reload.conf 56a60d600cd80a95f2e3b6909c3bda74
Description: Avahi mDNS/DNS-SD daemon
 Avahi is a fully LGPL framework for Multicast DNS Service Discovery.
 It allows programs to publish and discover services and hosts
 running on a local network with no specific configuration. For
 example you can plug into a network and instantly find printers to
 print to, files to look at and people to talk to.
 .
 This package contains the Avahi Daemon which represents your machine
 on the network and allows other applications to publish and resolve
 mDNS/DNS-SD records.
Homepage: http://avahi.org/
Original-Maintainer: Utopia Maintenance Team <email address hidden>

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Can you run avahi-discover (install the package avahi-discover if needed). Are your printers listed as IPP printers (Internet Printing Protocol)? If you run avahi-discover on a client, are the IPP printers of the server listed?

Revision history for this message
Mauro (jasmines) wrote :

Find attached avahi-discover screenshot. It seems no printers are listed.

Revision history for this message
gert (gert.cuykens) wrote :

 cat /var/log/boot.log
...
* Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ OK ]
* Starting cups-browsed - Bonjour remote printer browsing daemon [ OK ]
* Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ fail ]

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Mauro, can you follow the instructions of the section "CUPS error_log" on https://wiki.ubuntu.com/DebuggingPrintingProblems. Please boot your system (or restart avahi-daemon and cups manually, avahi-daemon first) and check whether your printers get broadcasted using avahi-discover. Now restart avahi-daemon and check whether this makes the broadcasting of your printers stop. After that attach the CUPS error_log.

Always attach files one by one and uncompressed, not packed together. This way one can quickly look into the files directly out of the browser.

Revision history for this message
Mauro (jasmines) wrote :

No printers discovered by avahi-discover after restarting of services nor after restarting again avahi-daemon.
Printers work correctly, however.

Don't know what else I can do, the issue still remains.

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

So if you restart avahi-daemon and after that restart cups you do not get your printers broadcasted?

Can you attach your /etc/cups/cupsd.conf, /etc/cups/cups-files.conf, /etc/cups/printers.conf, and /etc/avahi/avahi-daemon.conf files?

Revision history for this message
Mauro (jasmines) wrote :

Here you are with /etc/cups/cupsd.conf

Revision history for this message
Mauro (jasmines) wrote :

/etc/cups/cups-files.conf

Revision history for this message
Mauro (jasmines) wrote :

here you are with /etc/avahi/avahi-daemon.conf

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Mauro, are you actually sharing your printers? My cupsd.conf contains

----------
...
Browsing On
BrowseLocalProtocols dnssd
...
<Location />
  Order allow,deny
  Allow @LOCAL
</Location>
...
----------

Your cupsd.conf contains

----------
...
Browsing Off
BrowseLocalProtocols dnssd
...
<Location />
  Order allow,deny
</Location>
...
----------

What is the output of

cupsctl

Please run

cupsctl --share-printers

Do your printers get broadcasted via Avahi now?

Revision history for this message
Mauro (jasmines) wrote :

I'm referring to this report

I see two instances of the reload cups job in /var/log/boot.log, and the second one fails:
 * Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ OK ]
 * Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ fail ]

So the job triggers twice, it seems. Probably doesn't hurt anything, but looks bad. I'm on updated 13.04 (upgraded from 12.10).

Why should sharing printers solve the second fail?

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Mauro, I was assuming that printer broadcasting via Avahi does not work for you. Your cupsd.conf makes the impression to me that your CUPS is not sharing your printers and that you perhaps need to adjust your configuration.

If your printers are actually broadcasted and your only problem is the ugliness of a failed second attempt to restart CUPS reported in the logs the problem is much less severe (your printing functionality is fully available) and an Upstart expert has to look into this issue.

What is your situation? Are your printers still no broadcasted, even after following the instructions of comment #19?

Revision history for this message
Mauro (jasmines) wrote :

After following instructions in comment #19 and restarted cups, here is cupsctl output:

_debug_logging=0
_remote_admin=0
_remote_any=0
_share_printers=0
_user_cancel_any=0
BrowseLocalProtocols=dnssd
DefaultAuthType=Basic
JobPrivateAccess=default
JobPrivateValues=default
MaxLogSize=0
SubscriptionPrivateAccess=default
SubscriptionPrivateValues=default
SystemGroup=lpadmin
WebInterface=Yes

and after cupsctl --share-printers, avahi-discover finds all printers.

What now? :)

Revision history for this message
Till Kamppeter (till-kamppeter) wrote :

Mauro, the problem you have initially complained about is solved for you. Now the other machines in your network will find your printers.

Revision history for this message
Andres (flacoarmida) wrote :

I had the same problem. I did evrythin you said. Now printer is recognized by avahi-daemon and other pcs. But still the problem is there:
* Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ OK ]
 * Starting Reload cups, upon starting avahi-daemon to make sure remote queues are populated [ fail ]
and my printer doesnt print, it only eject blank sheets. I dont know what to do.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.