Ask Your Question

restart or reload service from puppet command line prompt

asked 2016-06-30 07:03:29 -0500

rahvee gravatar image

updated 2016-06-30 07:04:17 -0500

I have gotten in the habit, whenever I need to start or stop a service on an individual machine, of doing this:

puppet resource service nginx ensure=stopped enable=true

This has the nice benefit that I don't need to remember if this service uses /etc/init.d, or chkconfig, or service or systemctl

But I can only ensure=stoppped or ensure=running. How can I similarly restart or reload the service?

edit retag flag offensive close merge delete


Did you try: service nginx restart ?

rajeevsharma gravatar imagerajeevsharma ( 2016-06-30 09:12:36 -0500 )edit

As mentioned in the question, I'd like to use puppet for the benefit of abstraction - so I don't need to remember, on which platform to use `service` and when to use `systemctl` or whatever. Puppet figures that out.

rahvee gravatar imagerahvee ( 2016-07-01 06:40:11 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2016-07-02 21:08:00 -0500

Nizen gravatar image

Is this in the case of a configuration file change?

 class nginx {

  service { 'nginx':
    ensure  => 'running',
    enable  => true,
    require => Package['nginx'],

  file { '/etc/nginx/nginx.conf':
    notify  => Service['nginx'],
    mode    => '0600',
    owner   => 'nginx',
    group   => 'nginx',
    require => Package['nginx'],
    content => template('nginx/nginx.conf.erb'),

edit flag offensive delete link more

answered 2016-06-30 11:13:38 -0500

updated 2016-06-30 11:18:40 -0500

The only ensure values accepted are stopped and running unfortunately, see doco. Remember, Puppet is a declarative configuration management system that is used to specify the desired state for resources. What you really want is a feature in the puppet resource tool that could send refresh events to resources. As far as I'm aware, there's no such feature and I can't find any request to add such a feature.

edit flag offensive delete link more


Yes, that's exactly what I'm looking for - a way to trigger the 'refresh' event on a resource...

rahvee gravatar imagerahvee ( 2016-06-30 12:13:24 -0500 )edit

This is kind of hacky, but maybe something like `puppet resource notify refresh=service nginx` or something... But I haven't been able to make anything like that work (I'm a relative newbie.)

rahvee gravatar imagerahvee ( 2016-06-30 12:14:45 -0500 )edit

Well it's not going to work because there's no such feature. :) However, I think it could be a valid proposal for a feature request.

Alex Harvey gravatar imageAlex Harvey ( 2016-07-01 06:02:51 -0500 )edit

The best you could currently do would be to construct a puppet apply -e with a short enough expression, something like puppet apply -e "exec{'/bin/true':} ~> service{'nginx':}"

DarylW gravatar imageDarylW ( 2016-07-02 23:13:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-06-30 07:03:29 -0500

Seen: 321 times

Last updated: Jul 02 '16