How define twice the same service in Puppet?

谁都会走 提交于 2019-12-11 10:16:04

问题


In order to deploy Varnish with a Puppet class, I need stop Varnish for move and deploy files, then at the end, ensure that Varnish is started.

My problem is simple, how I can define twice a service in a Puppet class, in order to stop or start the service at differents steps ?

class varnish::install (

    (...)

    service { "varnish":
        ensure => "stopped",
        require => Package['varnish'],
        before => Exec['mv-lib-varnish'],
    }

    (...)

    service { "varnish":
        ensure => "running",
        require => File["$varnishncsa_file"],
    }
}

I've an Duplicate definition: Service[varnish] (...) error, and it's logical...

What's the best practice to manage services in a Puppet class ? Divide in multiple classes, or there is an option for "rename" a service for declare it several times ?


回答1:


try the following to get rid of duplicate error, but what you are trying to do is wrong. Puppet brings system to certain consistent state - so telling stop service X, do some work , start service X - it out of scope of proper puppet use, puppet is more like restart service if some files on which the service depends were modified.

class varnish::install (

(...)

service { "varnish-stop":
    name => "varnish"
    ensure => "stopped",
    require => Package['varnish'],
    before => Exec['mv-lib-varnish'],
}

(...)

service { "varnish-start":
    name => "varnish"
    ensure => "running",
    require => File["$varnishncsa_file"],
}
}



回答2:


Use exec with service restart as a hook (notify) for "deploy files" action (package/another exec). Define service itself only once as running, because that is what you normally want assuring. Puppet is for describing target state.



来源:https://stackoverflow.com/questions/11101752/how-define-twice-the-same-service-in-puppet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!