puppet - Puppet:有条件重启服务
问题描述
是否可以有条件地跳过service
资源上的刷新事件?或者:service
当类被通知时,是否可以防止类内的资源被刷新?
上下文:我有一个 Puppet 模块,其中包含以下清单(简化):
class foo(
Boolean pre_process_service = true,
Boolean auto_restart_service = true
) {
if $pre_process_service {
exec { 'process config':
... # details including a pretty complex command - should be hidden in my module
notify => Service['foo'],
}
}
service { 'foo':
ensure => 'running',
enable => true,
}
}
可以这样使用:
file { 'config':
... # copies config from somewhere
}
class { 'foo':
auto_restart_service => false,
subscribe => File['config'],
}
当用户指定时如何避免重新启动服务auto_restart_service => false
?
请注意,模块的用户决定如何提供配置(复制文件,签出 Git 存储库,......)所以我不能在我的模块中这样做。相反,该类订阅提供配置的资源。只要用户使用默认设置,auto_restart_service = true
一切都可以正常工作,甚至禁用配置的预处理也可以正常工作。但是,当用户指定时auto_restart_service = false
,服务仍然会重新启动,因为在service
通知类时会刷新资源。if
像我对资源所做的那样将服务资源包装到一个块exec
中也不起作用,因为service
资源做了多种事情:
- 如果服务没有运行,它会启动服务
- 如果未启用,它将启用服务
- 如果收到通知,它将重新启动服务
我只想有条件地防止(3)发生,同时总是做(1)和(2)。有没有办法做到这一点?
解决方案
我认为当您通知班级时没有办法不刷新服务。但是,您可以尝试使用资源的restart
属性有条件地覆盖 Puppet 应该如何重新启动服务service
。
像这样的东西:
if $auto_restart_service {
# Let the provider handle the restart
$_attr = {}
} else {
# Let Puppet execute `true` instead of actually restarting the service
$_attr = { 'restart' => '/usr/bin/true' }
}
service { 'foo':
ensure => 'running',
enable => true,
* => $_attr,
}
推荐阅读
- python - PySpark - 无法对 UDF groupby 操作结果执行任何操作
- python - 如何从 Python 中的模块的命名空间(内置函数)中排除函数?
- nginx - 从同一个入口公开 TCP 和 UDP
- php - “setcookie()”指令中的解析/语法错误
- cmd - 如何配置 blast+ 以访问外部硬盘驱动器上的数据库?
- python - 如何缩放 QPixmap 保留方面和居中图像?
- javascript - 一个插件输出 WordPress 的整数
- python - 设置或更改新 xarray 维度的值
- javascript - 如何在不转换的情况下访问内联脚本中的 PUG 传递对象
- javascript - 你如何抑制 kendoNumericTextBox 中不需要的小数位