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'`"
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue