我有一个这样的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
资源仅在 github 上找到更新并进行更改时重新启动设备应用程序vcsrepo
。
这是否可以单独使用 puppet,或者我应该编写一个 bash 脚本来检查上次更新.git
文件夹的时间?
您可以将元参数subscribe
和参数refreshonly
与exec
资源一起使用来完成此操作。
首先,使用subscribe
比喻计在vcsrepo
上建立exec
的排序关系,并检查资源更改:https://docs.puppet.com/puppet/latest/metaparameter.html#subscribe
接下来,使用refreshonly
指示exec
资源仅在vcsrepo
存储库生效更改(相对于非幂等(时才应用更改: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,
}
Matt Schuchard的回答对我不起作用。 由于"exec"中的"订阅",我一直收到来自puppet的错误:
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,
}