我有pp
这样的清单:
vcsrepo { '/home/pi/pop_machine':
ensure => latest,
provider => git,
source => 'https://github.com/kirkins/pop-machine-demo.git',
revision => 'master',
}
exec { 'npm start':
command => "/usr/bin/killall electron & /usr/bin/npm start",
cwd => "/home/pi/pop_machine/",
}
我希望exec
资源仅在vcsrepo
资源在github上发现更新并进行更改时重新启动设备应用程序。
单独使用puppet是可能的,还是应该编写一个bash脚本来检查.git
文件夹最后一次更新?
答案 0 :(得分:1)
您可以将元参数subscribe
和参数refreshonly
与exec
资源一起使用来实现此目的。
首先,使用subscribe
metaparmeter建立exec
vcsrepo
的排序关系,并检查资源变化:https://docs.puppet.com/puppet/latest/metaparameter.html#subscribe
接下来,使用refreshonly
指示exec
资源仅在vcsrepo
repo实现更改(对非幂等)时才应用更改:https://docs.puppet.com/puppet/latest/types/exec.html#exec-attribute-refreshonly
看起来像是:
vcsrepo { '/home/pi/pop_machine':
ensure => latest,
provider => git,
source => 'https://github.com/kirkins/pop-machine-demo.git',
revision => 'master',
}
exec { 'npm start':
command => "/usr/bin/killall electron & /usr/bin/npm start",
cwd => "/home/pi/pop_machine/",
subscribe => Vcsrepo['/home/pi/pop_machine'],
refreshonly => true,
}
答案 1 :(得分:0)
Matt Schuchard's 答案对我不起作用。由于“exec”中的“订阅”,我不断收到来自木偶的错误:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Could not autoload puppet/type/vcsrepo: Attempt to redefine entity 'http://puppet.com/2016.1/runtime/type/vcsrepo'.
但这确实对我有用:
vcsrepo { '/home/pi/pop_machine':
ensure => latest,
provider => git,
source => 'https://github.com/kirkins/pop-machine-demo.git',
revision => 'master',
notify => Exec['npm start'],
}
exec { 'npm start':
command => "/usr/bin/killall electron & /usr/bin/npm start",
cwd => "/home/pi/pop_machine/",
refreshonly => true,
}