diff --git a/puppet/files/puppet-check b/puppet/files/puppet-check index 22958fb..2fe60ca 100755 --- a/puppet/files/puppet-check +++ b/puppet/files/puppet-check @@ -1,13 +1,31 @@ -#!/bin/sh +#!/usr/bin/env ruby -PID="`pgrep -f 'puppetd'`" -if [ $? -ne 0 ]; then - echo "puppetd not running on host `hostname`" - exit 1 -fi +require "puppet" +require "socket" -MEMUSAGE=`ps -p ${PID} -o rss | tail -1` -if [ ${MEMUSAGE} -gt 262144 ]; then - echo "puppetd process size is over 256 MB (${MEMUSAGE} KB), restart recommended" - exit 1 -fi +Puppet.parse_config + +# get pid number for puppet or exit if not found +pidfile = Puppet.settings.value("rundir") + "/puppetd.pid" +begin + pid = File.new(pidfile, "r").read.to_i +rescue Errno::ENOENT + exit +end + +# check that process is still alive +begin + Process.kill(0, pid) + exit +rescue Errno::ESRCH + nil +end + +# restart +printf("puppetd dead but pid file exists on host '%s', restarting\n", + Socket.gethostname) +begin + exec("service puppet start") +rescue Errno::ENOENT + exec("puppetd") +end