停止 tomcat 服务后,我需要执行一些操作(配置某些内容)。配置完成后,我需要确保 tomcat 服务再次启动并运行。我为此编写了以下 puppet 代码:
Service {'tomcat': ensure => stopped }
->
class {'config':}
->
Service {'tomcat': ensure => running }
在 puppet 应用上,它提示
'Error: Duplicate declaration: Service[tomcat] is already declared in file'
如何解决这个问题。 puppet 中停止服务、执行某些操作然后再次恢复服务的方法是什么?
最佳答案
在 puppet 中,您无法再次声明相同的服务。这就是你的错误。
使用 puppet,您无需关心 tomcat 停止/启动进程。它负责最终状态(称为“idemoteency”)。定义包、配置文件和服务之间的关系后,它将为您完成所有工作。例如,您需要了解puppet中的以下流程以及->
和~>
之间的区别。
Package['tomcat'] -> File['server.xml'] ~> Service['tomcat']
在您的情况下,您应用 tomcat 配置文件中的更改,puppet 将自动重新启动 tomcat 服务。
以下是来自 Introduction to Puppet 的复制粘贴,供您引用。博客解释幂等性的含义:
One big difference between Puppet and most other tools is that Puppet configurations are idempotent, meaning they can safely be run multiple times. Once you develop your configuration, your machines will apply the configuration often — by default, every 30 minutes — and Puppet will only make any changes to the system if the system state does not match the configured state.
2016 年更新:
这是另一篇关于幂等性的官方 Puppet 博客文章:https://puppet.com/blog/idempotence-not-just-a-big-and-scary-word
关于puppet - 在 puppet 中,如何停止服务,执行某些操作然后启动服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27636291/