Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got a file that notifies the puppet agent.

In the network module, the proxy settings are included in the .gemrc file like this:

file { "/root/.gemrc":
  content => "http_proxy: $http_proxy\n",
  notify => Service['puppet'],
}

The problem is that puppet stops and does not restart.

Aug 31 12:05:13 snch7log01 puppet-agent[1117]: (/Stage[main]/Network/File[/root/.gemrc]/content) content changed '{md5}2b00042f7481c7b056c4b410d28f33cf' to '{md5}60b725f10c9c85c70d97880dfe8191b3'
Aug 31 12:05:13 snch7log01 puppet-agent[1117]: Caught TERM; calling stop

I assume the code does something like /etc/init.d/puppet stop && /etc/init.d/puppet start Since puppet is not running, it cannot start itself... it kind of makes sense.

How to make puppet restart itself when this file changes? Note that this file may not exist as well.

share|improve this question
    
I don't really have the answer to your question, but have you investigated running puppet agent from crontab? It could pick up the changes in your file and it wouldn't leave in memory a process which ultimately wakes up at given intervals. –  sebastianopilla Aug 31 '12 at 12:51
    
I thought about creating a crontab which starts puppet if it's down... This might work but I don't think it's the best way to go. –  SamK Aug 31 '12 at 12:56

3 Answers 3

up vote 4 down vote accepted

You may need to add to the service resource declaration for 'puppet':

hasrestart => true,
share|improve this answer

I had a similar problem. I needed to deploy fixes to augeas, and used puppet to deploy them, but they would not take effect until puppetd was restarted. So I needed a quick and easy way to tell puppetd to restart one time. I solved this with a shell script and an exec.

Here is the script:

#!/bin/bash
if [ X"$1" != Xbackground ]; then
    OUTDIR=/var/log/puppet
    mkdir -p $OUTDIR
    nohup $0 background > $OUTDIR/puppet_restart.out 2>&1 < /dev/null &
    exit 0
fi

#  If you get here, this is a background copy of this script that has
#  been decoupled from puppet by the nohup above.  Give puppet a chance
#  to finish what it is doing, then restart it.

sleep 60

/sbin/service puppet restart

The manifest to run the script makes use of the log file it creates. (This works fine for the first time - if you make subsequent updates, make a manifest that will delete the log file so this will run one time again):

file { "/usr/local/bin/puppet_restart":
    owner => root,
    group => root,
    mode  => 750,
    source => "puppet:///modules/puppet_fix_module/puppet_restart"
}

exec { "restart_puppet":
    command => "/usr/local/bin/puppet_restart",
    path    => ["/usr/bin", "/usr/sbin", "/bin"],
    creates => "/var/log/puppet/puppet_restart.out",
    require => [ File['/usr/local/bin/puppet_restart'],
                 File ["/some/other/file/that/requires/restart"],
               ]
}
share|improve this answer

In addition to making sure that "hasrestart" is in the manifest, you should also make sure that

"ensure => running"

Is in the manifest. Here is my copy:

class puppet::service {
  service { puppet:
    ensure => running,
    enable  => true,
    hasrestart => true,
    subscribe => File["/etc/puppet/puppet.conf"],
  }     
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.