puppet - 在 puppet 中,如何停止服务,执行某些操作然后启动服务?

标签 puppet

停止 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/

相关文章:

vagrant - 如何从本地VirtualBox/Vagrant开发环境完成生产部署?

puppet - 在 puppet 中 @@ 叫什么,它有什么作用?

使用 join 的 Puppet 模块可以在生产环境中工作,但会破坏测试

puppet - 从 git repo 克隆后,如何使用 puppet 在 nodejs-application 上运行 npm install

ruby - 如何使用 Puppet 文件资源为目录授予与其文件不同的权限?

linux - 错误:无法应用目录:nil:NilClass的未定义方法“祖先”

python - 类似 python 的 puppet 语法

vagrant - 如何在 Puppet 配置的 Vagrant 项目中跨环境共享 list

Puppet 找不到 bundler 命令

virtualization - 如何使用 Vagrant box 打包文件?