这是有道理的,而且实际上也是建议 在这个网站上,使用 puppet 元参数(例如通知或订阅)让关键文件更改触发服务重启。例如:
## file definition for printers.conf
file { "/etc/cups/printers.conf":
[snip],
source => "puppet:///module/etc/cups/printers.conf"
}
## service definition for sshd
service { 'cups':
ensure => running,
subscribe => File['/etc/cups/printers.conf']
}
但在 CUPS 的情况下,这会触发无限循环的重启;其逻辑如下:
- 更改 puppetmaster 的版本
/etc/cups/printers.conf
- puppetmaster 将新版本推送到客户端,触发 cups 重启
- cupsd restart 坚持将其自己的时间戳放在 Printers.conf 的顶部,“由 cupsd 编写...”
- 这种改变将被视为过时,因此之后
runinterval
我们回到(1)。
有没有办法让 cupsd 不再需要为文件添加时间戳?或者有什么办法可以帮上忙?
谢谢!
答案1
您可以将文件复制到另一个名称,并让 exec 仅在 Printers.conf 不包含您需要的行时才进行复制。例如。
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"],
}
答案2
另一种方法是lpadmin
将打印机添加到 CUPS,以防 Printers.conf 中缺少该打印机。
例如:
exec {
"/usr/sbin/lpadmin -p Lexmark-E450 -E -v usb://Lexmark/E450 -P /path/to/Lexmark_E450.ppd":
unless => "/bin/grep Lexmark-E450 /etc/cups/printers.conf 2>/dev/null",
require => File["/path/to/Lexmark_E450.ppd"];
}
这样,我们就避免了在 CUPS 运行时弄乱 Printers.conf。要删除打印机,我们可以使用lpadmin -x PRINTER-NAME
(请参阅lpadmin 手册页)
更具体的例子:
class print-common::lex250 {
exec {
"/usr/sbin/lpadmin -p Lexmark-E250 -E -v usb://Lexmark/E250d -P /path/to/PRINTER.ppd":
unless => "/bin/grep Lexmark-E250 /etc/cups/printers.conf 2>/dev/null",
require => File["/path/to/PRINTER.ppd"];
}
}
class print-common {
package {
"cups": ensure => installed;
}
service {
"cups":
ensure => running,
require => Package["cups"],
subscribe => File["/etc/cups/cupsd.conf"];
}
file {
"/etc/cups/cupsd.conf":
ensure => present,
owner => root,
group => root,
mode => 644,
source => "puppet://puppet.mr.lan/files/etc/cups/cupsd.conf";
"/path/to/ppd/":
ensure => directory;
"/path/to/PRINTER.ppd":
ensure => present,
owner => root,
group => root,
mode => 644,
source => "puppet://puppet.mr.lan/files/path/to/PRINTER.ppd",
require => File["/path/to/ppd/"];
}
case $fqdn {
'host1.domain.name','host2.domain.name': { include print-common::lex250 }
}
}
然后可能print-common::lex250
就可以将其分解为可重复使用的东西,使用变量魔法等。
答案3
由于cupsd
坚持要修改,printers.conf
您无法替换整个文件,而是需要逐行修改。查看
http://projects.puppetlabs.com/projects/puppet/wiki/Simple_Text_Patterns
它将向您展示如何替换文件的各个部分。
答案4
我之前见过这个问题,看起来它将被 CUPS 1.4.7 中的上游修复,所以只有在发生了更改时它才会重写文件(更新时间戳)。
Fedora Bug #565674 描述1此修复程序,并且 Debian 曾经携带过一个阻止写入时间戳的补丁。