Changed max mem usage to 128M and added syslog support.
This commit is contained in:
parent
d523669f18
commit
1538e22eda
1 changed files with 23 additions and 8 deletions
|
@ -1,8 +1,12 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require "puppet"
|
require "puppet"
|
||||||
|
require "syslog"
|
||||||
require "socket"
|
require "socket"
|
||||||
|
|
||||||
|
Syslog.open(File.basename(__FILE__), Syslog::LOG_PID | Syslog::LOG_NDELAY,
|
||||||
|
Syslog::LOG_DAEMON)
|
||||||
|
|
||||||
Puppet.parse_config
|
Puppet.parse_config
|
||||||
|
|
||||||
if Puppet.version[/\d+/].to_i >= 2
|
if Puppet.version[/\d+/].to_i >= 2
|
||||||
|
@ -13,11 +17,15 @@ else
|
||||||
pidname = "puppetd.pid"
|
pidname = "puppetd.pid"
|
||||||
end
|
end
|
||||||
|
|
||||||
# get pid number for puppet or exit if not found
|
# get pid number for puppet or warn if not found
|
||||||
pidfile = File.join(Puppet.settings.value("rundir"), pidname)
|
pidfile = File.join(Puppet.settings.value("rundir"), pidname)
|
||||||
begin
|
begin
|
||||||
pid = File.new(pidfile, "r").read.to_i
|
pid = File.new(pidfile, "r").read.to_i
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
|
err = sprintf("puppetd not running on host '%s'\n", Socket.gethostname)
|
||||||
|
Syslog.info sprintf(err)
|
||||||
|
print err
|
||||||
|
Syslog.close
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,16 +35,20 @@ begin
|
||||||
|
|
||||||
# check memory usage and restart if over 256M
|
# check memory usage and restart if over 256M
|
||||||
rss = `ps -o rss -p '#{pid}'`.to_a.last.to_i / 1024
|
rss = `ps -o rss -p '#{pid}'`.to_a.last.to_i / 1024
|
||||||
if rss > 256
|
if rss > 128
|
||||||
printf("puppetd memory usage too high (%d MB), on host '%s' sending HUP\n",
|
err = sprintf("puppetd memory usage too high (%d MB), on host '%s' sending HUP\n",
|
||||||
rss, Socket.gethostname)
|
rss, Socket.gethostname)
|
||||||
|
Syslog.warning err
|
||||||
|
print err
|
||||||
Process.kill("HUP", pid)
|
Process.kill("HUP", pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if deadlock file is too old
|
# check if deadlock file is too old
|
||||||
dlock = Puppet.settings.value("puppetdlockfile")
|
dlock = Puppet.settings.value("puppetdlockfile")
|
||||||
if File.exists?(dlock) and Time.new - File.new(dlock).mtime > 43200
|
if File.exists?(dlock) and Time.new - File.new(dlock).mtime > 43200
|
||||||
print "puppetd deadlock file is over 12 hours old, removing it and sending HUP to daemon\n"
|
err = "puppetd deadlock file is over 12 hours old, removing it and sending HUP to daemon\n"
|
||||||
|
Syslog.warning err
|
||||||
|
print err
|
||||||
File.unlink(dlock)
|
File.unlink(dlock)
|
||||||
Process.kill("HUP", pid)
|
Process.kill("HUP", pid)
|
||||||
end
|
end
|
||||||
|
@ -47,7 +59,10 @@ rescue Errno::ESRCH
|
||||||
end
|
end
|
||||||
|
|
||||||
# restart
|
# restart
|
||||||
printf("puppetd dead but pid file exists on host '%s', restarting\n",
|
err = sprintf("puppetd dead but pid file exists on host '%s', restarting\n",
|
||||||
Socket.gethostname)
|
Socket.gethostname)
|
||||||
system("service puppet start")
|
Syslog.warning err
|
||||||
|
system("service puppet start > /dev/null")
|
||||||
system(puppetd) if $?.exitstatus == 127
|
system(puppetd) if $?.exitstatus == 127
|
||||||
|
Syslog.close
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue