Puppet:停止单个节点上的服务 [英] Puppet: stopping service on individual nodes

查看:69
本文介绍了Puppet:停止单个节点上的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

木偶有时会很令人沮丧.

Puppet can be so frustrating sometimes.

我有多个节点使用贵宾犬"服务,并且已经以这种方式进行了配置.

I have multiple nodes that use a service "poodle", and it has been configured this way.

# SITE.PP
node 'tweedle.example.com' {
    include basicstuff
    include poodle
}

node 'beetle.example.com' {
    include basicstuff
    include poodle
}

## POODLE MODULE, manifests/init.pp
class poodle {
    class {'poodle::install': }
    class {'poodle::config': }
    class {'poodle::service': }

    Class ['poodle::install'] -> Class ['poodle::config'] ~> Class ['poodle::service']
}

...

class poodler::service {
    service {'poodle':
        ensure     => 'running',
        enable     => true,
        restart    => "/etc/init.d/poodle stop && sleep 5 && /etc/init.d/poodle start",
        subscribe  => File['/opt/poodle/poodle.py'],
    }
}

现在,假设我不再需要在甲虫"机器上运行贵宾犬.如何仅在该机器上停止服务?

Now, let's say that I no longer need to run poodle on the "beetle" machine. How do I go about stopping the service on only that machine?

我试过通过 ensure => 停止,但出现语法错误:

I've tried passing ensure => stopped, but I get a syntax error:

node 'beetle.example.com' {
    include basicstuff
    class poodle::service {
         ensure => 'stopped'
    }
}

或者也许?

node 'beetle.example.com' {
    include basicstuff
    include poodle::service {
         ensure => 'stopped'
    }
}

推荐答案

在你的服务类中添加一个参数,可以用于服务上的 ensure 参数,像这样

Add a parameter to your service class that can be used for the ensure parameter on the service, like so

class poodler::service ($ensure = 'running') {
    service {'poodle':
        ensure     => $ensure,
        enable     => true,
        restart    => "/etc/init.d/poodle stop && sleep 5 && /etc/init.d/poodle start",
        subscribe  => File['/opt/poodle/poodle.py'],
    }
}

然后,不要像第二次尝试那样包含类,而是将类创建为资源并设置 $ensure 的值.

Then instead of including the class like your second attempt does, create the class as a resource and set the value of $ensure.

node 'beetle.example.com' {
    include basicstuff
    class {'poodle::service':
         ensure => 'stopped',
    }
}

那应该会终止服务.

由于 $ensure 参数的默认设置为 running,因此您无需在实际希望它运行时指定它.

Since the default for the $ensure paramater is set to running, you don't need to specify that when you actually want it running.

如果您愿意,可以参数化您的类的其他部分,如果您愿意,这可能会导致应用程序被完全删除.

Can parameterize other parts of your classes if you want that could cause the app to be completely removed if you wanted to.

关于这个主题的好读物是:Learning Puppet — 类参数

Good reading on this subject is at: Learning Puppet — Class Parameters

这篇关于Puppet:停止单个节点上的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆