Rewrote puppet-check using ruby and added automatic restart if puppetd process is dead.
This commit is contained in:
parent
b5e8c6b7fe
commit
8d8b496078
1 changed files with 29 additions and 11 deletions
|
@ -1,13 +1,31 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
PID="`pgrep -f 'puppetd'`"
|
require "puppet"
|
||||||
if [ $? -ne 0 ]; then
|
require "socket"
|
||||||
echo "puppetd not running on host `hostname`"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
MEMUSAGE=`ps -p ${PID} -o rss | tail -1`
|
Puppet.parse_config
|
||||||
if [ ${MEMUSAGE} -gt 262144 ]; then
|
|
||||||
echo "puppetd process size is over 256 MB (${MEMUSAGE} KB), restart recommended"
|
# get pid number for puppet or exit if not found
|
||||||
exit 1
|
pidfile = Puppet.settings.value("rundir") + "/puppetd.pid"
|
||||||
fi
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue