forked from leoarnold/puppet-cups
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid ipptool errors when Cups is slow to start
Problem statement: on some OSes (most notably RHEL7 and derivatives), the Cups service may have started and not listen on the IPP port yet. This causes a problem when this module (re)starts the service and expects to be able to add/remove printers with ipptool right after. Thus, modify the standard cups.socket service on RHEL7 through a drop-in to also manage the IPP port. This way, systemd will accept the incoming connections and hand them off to Cups once it is really started. This is mostly a kludge for a 3rd party bug, but still required to make the module behave reliably. Fix some cases of leoarnold#35. Breaking changes: - Bump the Puppet minimum version to 4.10.0 for Hiera 5. - Depend on puppetlabs/stdlib and camptocamp/systemd (and its dependency puppetlabs/inifile).
- Loading branch information
Showing
12 changed files
with
182 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
cups::socket_manage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
version: 5 | ||
hierarchy: | ||
- name: OS configuration | ||
path: "os/%{facts.os.family}-%{facts.os.release.major}.yaml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# @private | ||
# | ||
# @summary Avoid ipptool errors when Cups is slow to start | ||
# | ||
# Problem statement: on some OSes (most notably RHEL7 and derivatives), the | ||
# Cups service may have started and not listen on the IPP port yet. This causes | ||
# a problem when this module (re)starts the service and expects to be able to | ||
# add/remove printers with ipptool right after. | ||
# | ||
# If `$cups::socket_manage` is enabled, this class modifies the standard | ||
# `cups.socket` service to also manage the IPP port. This way, systemd will | ||
# accept the incoming connections and hand them off to Cups once it is really | ||
# started. This is mostly a kludge for a 3rd party bug, but still required to | ||
# make the module behave reliably. | ||
# | ||
# If `$cups::socket_manage` is disabled, this workaround is removed. | ||
# | ||
# The `$cups::socket_ensure` argument may optionnally be set to `stopped`, and | ||
# this setting should probably match `$cups::service_ensure`. | ||
# | ||
# The `$cups::service_names` argument is used to generate the socket services, | ||
# ie. each X.service will have its X.socket managed as described above. | ||
# | ||
# @author Thomas Equeter | ||
# @since 3.0.0 | ||
# | ||
class cups::server::socket inherits cups::server { | ||
|
||
$_dropin_file = systemd::dropin_file { 'workaround-puppet-cups-35.conf': | ||
ensure => if $cups::socket_manage { 'present' } else { 'absent' }, | ||
unit => 'cups.socket', | ||
content => @(END), | ||
[Socket] | ||
ListenStream=[::1]:631 | ||
|END | ||
} | ||
|
||
if $cups::socket_manage { | ||
Array($cups::service_names, true).each |$_service_name| { | ||
$_safe_name = shell_escape($_service_name) | ||
|
||
service { "${_service_name}.socket": | ||
ensure => $cups::socket_ensure, | ||
# Both units listen to port 631, however cups.service will play nice if | ||
# cups.socket is started first. See sd_listen_fds(3). | ||
start => "systemctl stop ${_safe_name}.service && systemctl start ${_safe_name}.socket", | ||
restart => "systemctl stop ${_safe_name}.service && systemctl restart ${_safe_name}.socket", | ||
require => Class['systemd::systemctl::daemon_reload'], | ||
subscribe => $_dropin_file, | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper_acceptance' | ||
|
||
RSpec.describe 'Custom type `cups_queue`' do | ||
describe 'when the Cups service is starting' do | ||
before(:each) do | ||
ensure_cups_is_running | ||
# Cups takes time to listen to IPP after service start, depending on the | ||
# amount of printers defined. Just a few printers are enough to cause the | ||
# cups_queue ipptool calls to fail right after a restart, but adding 50 | ||
# here makes it future-proof for the ever-faster testing environments. | ||
printer_names = (1..50).map { |n| "Office#{n}" } | ||
printer_names.each do |name| | ||
shell("lpadmin -E -p #{name} -m drv:///sample.drv/generic.ppd -o printer-is-shared=false", silent: true) | ||
end | ||
remove_queues('Office') | ||
|
||
# Cleanup | ||
if fact('systemd') then | ||
shell('rm -f /etc/systemd/system/cups.socket.d/workaround-puppet-cups-35.conf') | ||
shell('systemctl daemon-reload', accept_all_exit_codes: true) | ||
shell('systemctl stop cups.socket cups.service', accept_all_exit_codes: true) | ||
else | ||
# Not needed, but for coherence with the systemd version | ||
shell('service cups stop') | ||
end | ||
end | ||
|
||
manifest = <<-MANIFEST | ||
class { 'cups': | ||
service_ensure => 'running', | ||
} | ||
cups_queue { 'Office': | ||
ensure => 'printer', | ||
} | ||
MANIFEST | ||
|
||
it 'can refresh the service and create a queue' do | ||
# Do NOT use ensure_cups_is_running here, it calls the cups class and | ||
# installs the dropin file, which is exactly what we want to test below. | ||
shell('service cups start') | ||
# Cause a rewrite of the configuration and trigger a service refresh. | ||
shell('rm /etc/cups/cupsd.conf') | ||
apply_manifest(manifest, expect_changes: true) | ||
end | ||
|
||
it 'can start the service and create a queue' do | ||
apply_manifest(manifest, expect_changes: true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters