木偶检测文件是否更改但不更改它
puppet detect if a file changed but don't change it
我想用 puppet 管理 jenkins-service 的 config.xml 文件。问题是,如果 Puppet 更改 config.xml 文件并重新启动 jenkins 服务,config.xml 文件将被当前加载的 jenkins 配置覆盖,并且 puppet 所做的更改将丢失。
这就是我现在拥有的:
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644'
}
service { 'jenkins':
ensure => running,
enable => true,
subscribe => File['/var/lib/jenkins/config.xml']
}
我的方法是停止 jenkins 服务,而不是复制 config.xml 并再次启动该服务...当然,每次 puppet 运行时不应停止并重新启动该服务,但前提是 config.xml 改变了。我不知道如何用木偶做到这一点,即使有可能。有什么想法吗?
如有任何帮助,我们将不胜感激
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
notify => Service["jenkins"]
}
service { 'jenkins':
ensure => running,
enable => true,
subscribe => File['/var/lib/jenkins/config.xml']
}
这将在初始创建或更改文件时通知服务 jenkins。
用 puppet 处理这件事有点痛苦,但一种方法是检测暂存文件的更改,然后使用 exec 对文件更改进行排序:
file { '/some/staging/path/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
notify => Exec['Update Jenkins Config']
}
exec { 'Update Jenkins Config':
command => '/sbin/service jenkins stop && /bin/cp /some/staging/path/config.xml /var/lib/jenkins/config.xml && /sbin/service jenkins start',
refreshonly => true
}
另一种方法是使用 transition module。
这是一个例子:
transition { 'stop jenkins service':
resource => Service['jenkins'],
attributes => { ensure => stopped },
prior_to => File['/var/lib/jenkins/config.xml'],
}
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
}
service { 'jenkins':
ensure => running,
enable => true,
}
我想用 puppet 管理 jenkins-service 的 config.xml 文件。问题是,如果 Puppet 更改 config.xml 文件并重新启动 jenkins 服务,config.xml 文件将被当前加载的 jenkins 配置覆盖,并且 puppet 所做的更改将丢失。
这就是我现在拥有的:
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644'
}
service { 'jenkins':
ensure => running,
enable => true,
subscribe => File['/var/lib/jenkins/config.xml']
}
我的方法是停止 jenkins 服务,而不是复制 config.xml 并再次启动该服务...当然,每次 puppet 运行时不应停止并重新启动该服务,但前提是 config.xml 改变了。我不知道如何用木偶做到这一点,即使有可能。有什么想法吗?
如有任何帮助,我们将不胜感激
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
notify => Service["jenkins"]
}
service { 'jenkins':
ensure => running,
enable => true,
subscribe => File['/var/lib/jenkins/config.xml']
}
这将在初始创建或更改文件时通知服务 jenkins。
用 puppet 处理这件事有点痛苦,但一种方法是检测暂存文件的更改,然后使用 exec 对文件更改进行排序:
file { '/some/staging/path/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
notify => Exec['Update Jenkins Config']
}
exec { 'Update Jenkins Config':
command => '/sbin/service jenkins stop && /bin/cp /some/staging/path/config.xml /var/lib/jenkins/config.xml && /sbin/service jenkins start',
refreshonly => true
}
另一种方法是使用 transition module。 这是一个例子:
transition { 'stop jenkins service':
resource => Service['jenkins'],
attributes => { ensure => stopped },
prior_to => File['/var/lib/jenkins/config.xml'],
}
file { '/var/lib/jenkins/config.xml':
source => 'puppet:///modules/jenkins/config.xml',
owner => jenkins,
group => jenkins,
mode => '0644',
}
service { 'jenkins':
ensure => running,
enable => true,
}