From 51865fd8bfacc87e1ab85d560eb4f182a5d9113c Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 19 Feb 2011 19:14:12 -0200 Subject: Enhancing check-puppetd.sh --- files/check-puppetd.sh | 17 ----------------- files/cron.d/puppetd | 1 - files/cron.d/puppetmaster | 1 - manifests/puppetd.pp | 14 +++++++------- templates/check-puppetd.sh.erb | 21 +++++++++++++++++++++ templates/puppet-node.conf.erb | 2 +- 6 files changed, 29 insertions(+), 27 deletions(-) delete mode 100644 files/check-puppetd.sh create mode 100644 templates/check-puppetd.sh.erb diff --git a/files/check-puppetd.sh b/files/check-puppetd.sh deleted file mode 100644 index 10d6bc1..0000000 --- a/files/check-puppetd.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# -# check if puppet is running -# - -PID="/var/run/puppet/agent.pid" -INIT="/etc/init.d/puppet" - -if [ ! -f "$PID" ]; then - $INIT start -else - running="$(ps $(cat $PID) &> /dev/null)" - if [ "$?" != "0" ]; then - sleep `echo $RANDOM/2000*60 | bc` - $INIT start - fi -fi diff --git a/files/cron.d/puppetd b/files/cron.d/puppetd index 5a45875..2cb9acf 100644 --- a/files/cron.d/puppetd +++ b/files/cron.d/puppetd @@ -1,3 +1,2 @@ # restart puppet once in a while and randomly delay the restart between 0 and 32 minutes -> splay puppetmaster hammering 0 22 * * */2 root sleep `echo $RANDOM/1000*60 | bc` && /etc/init.d/puppet restart > /dev/null - diff --git a/files/cron.d/puppetmaster b/files/cron.d/puppetmaster index 4ea0b66..8ddbe54 100644 --- a/files/cron.d/puppetmaster +++ b/files/cron.d/puppetmaster @@ -1,3 +1,2 @@ # we restart puppetmaster twice a day to avoid memory problems 58 11 * * * root /etc/init.d/puppetmaster restart > /dev/null - diff --git a/manifests/puppetd.pp b/manifests/puppetd.pp index 66edf43..7f00241 100644 --- a/manifests/puppetd.pp +++ b/manifests/puppetd.pp @@ -32,9 +32,9 @@ class puppetd inherits puppet { # name of puppet agent section in config file if $puppetversion <= "0.25.4" { - $puppet_agent_section = 'puppetd' + $puppet_agent_name = 'puppetd' } else { - $puppet_agent_section = 'agent' + $puppet_agent_name = 'agent' } # default config file for puppet nodes @@ -59,11 +59,11 @@ class puppetd inherits puppet { } file { "/usr/local/sbin/check-puppetd.sh": - source => "puppet://$server/modules/puppet/check-puppetd.sh", - owner => "puppet", - group => "puppet", - mode => 0755, - ensure => present, + content => template("puppet/check-puppetd.sh.erb"), + owner => "puppet", + group => "puppet", + mode => 0755, + ensure => present, } cron { "puppetd-check": diff --git a/templates/check-puppetd.sh.erb b/templates/check-puppetd.sh.erb new file mode 100644 index 0000000..639a1d5 --- /dev/null +++ b/templates/check-puppetd.sh.erb @@ -0,0 +1,21 @@ +#!/bin/bash +# +# check if puppet is running +# + +PID="/var/run/puppet/<%= puppet_agent_name %>.pid" +INIT="/etc/init.d/puppet" + +function puppet_start { + sleep `echo $RANDOM/2000*60 | bc` + $INIT start +} + +if [ ! -f "$PID" ]; then + puppet_start +else + running="$(ps $(cat $PID) &> /dev/null)" + if [ "$?" != "0" ]; then + puppet_start + fi +fi diff --git a/templates/puppet-node.conf.erb b/templates/puppet-node.conf.erb index 033c2e5..f8b1b32 100644 --- a/templates/puppet-node.conf.erb +++ b/templates/puppet-node.conf.erb @@ -6,7 +6,7 @@ rundir = /var/run/puppet factpath = $vardir/lib/facter pluginsync = true -[<%= puppet_agent_section %>] +[<%= puppet_agent_name %>] vardir = /var/lib/puppet ssldir = $vardir/ssl server = puppet.<%= domain %> -- cgit v1.2.3