Puppet causes endless restarts of CUPS (how does one prevent this)


It makes sense, and is in fact suggested
on this site, to have a critical file change trigger a service restart with puppet meta-parameters (such as notify or subscribe). For example:

  ## file definition for printers.conf
  file { "/etc/cups/printers.conf":
    source => "puppet:///module/etc/cups/printers.conf"

  ## service definition for sshd
  service { 'cups':
    ensure => running,
    subscribe => File['/etc/cups/printers.conf']

But in the case of CUPS, this triggers and endless loop of restarts; the logic works like this:

  1. Change puppetmaster's version of
  2. puppetmaster pushes new version to
    client, triggering cups restart
  3. cupsd restart insists on putting its own
    time stamp at the top of
    printers.conf, 'Written by cupsd…'
  4. This change will be seen as out of
    date, so after runinterval, we
    return to (1).

Is there a way to suppress cupsd's need to time stamp the file? Or is there a puppet trick that could help here?


Best Answer

You could copy the file to another name, and have an exec to only copy if printers.conf doesn't contain a line you require. Eg.

    file { "/etc/cups/printers.conf.puppet":
                source  => "puppet:///modules/desktop/cups/printers.conf",
                mode    => 0600,
                owner   => root,
                group   => lp;

    # cups will put it's own timestamp in printers.conf, causing a loop if
    # puppet always replaces if the timestamp is different. This only replaces
    # the file is HP-Laserjet is not present
    exec { "/bin/cp /etc/cups/printers.conf.puppet /etc/cups/printers.conf":
            unless => '/bin/grep "HP-LaserJet-2300" /etc/cups/printers.conf 2>/dev/null',
            subscribe => File["/etc/cups/printers.conf.puppet"],
            refreshonly => "true",
            require => Package["cups"],
            notify => Service["cups"],
Related Topic