傀儡:在覆盖文件之前停止服务

我有以下简化的configuration:

file { '/etc/foo.conf': ensure => file, content => epp('my_module/etc/foo.conf.epp'), ; } service { 'foo': ensure => running, enable => true, subscribe => File['/etc/foo.conf'], ; } 

当我更新模板时,puppet覆盖/etc/foo.conf然后重新启动服务。

我的问题是我需要覆盖文件之前停止服务因为当服务停止时,将其在内存中的configuration写回文件。

有没有办法用木偶做呢?

看看转换模块 。 有了这个,你可以做这样的事情:

 transition { 'stop foo service': resource => Service['foo'], attributes => { ensure => stopped }, prior_to => File['/etc/foo.conf'], } file { '/etc/foo.conf': ensure => file, content => epp('my_module/etc/foo.conf.epp'), } service { 'foo': ensure => running, enable => true, subscribe => File['/etc/foo.conf'], } 

没有exec的要求。

你可以做这样的事情:

 file { '/etc/foo.conf.tmp': ensure => file, content => epp('my_module/etc/foo.conf.epp'), } exec { 'stop service': command => 'service foo stop', refreshonly => true, subscribe => File['/etc/foo.conf.tmp'] } exec { 'update file': command => 'cp /etc/foo.conf.tmp /etc/foo.conf', subscribe => Exec['stop service'], refreshonly => true, } exec { 'start service': command => 'service foo start', subscribe => Exec['update file'], refreshonly => true, } 

exec资源的refreshonly属性将确保命令只在收到事件时运行,在这种情况下,通过subscribe属性。 在这种情况下,只有当您的tmp设置文件被更改时,它才会停止服务器并复制新的设置文件。 tmp文件将允许您pipe理服务器上的设置,而不必覆盖服务。

你可以把这三个exec成一个命令

 file { '/etc/foo.conf.tmp': ensure => file, content => epp('my_module/etc/foo.conf.epp'), } exec { 'update settings': command => 'service foo stop && cp /etc/foo.conf.tmp /etc/foo.conf && service foo start', refreshonly => true, subscribe => File['/etc/foo.conf.tmp'] }