diff --git a/codepot/codepot.spec.in b/codepot/codepot.spec.in index 0a8c519d..95f07709 100644 --- a/codepot/codepot.spec.in +++ b/codepot/codepot.spec.in @@ -68,6 +68,7 @@ rm -rf $RPM_BUILD_ROOT /var/www/html/codepot /usr/sbin/codepot-user +/usr/sbin/codepot-mon-httpd %config(noreplace) /etc/codepot/codepot.ini /etc/codepot/codepot.mysql diff --git a/codepot/sbin/Makefile.am b/codepot/sbin/Makefile.am index c002e3b2..fc92b9fb 100644 --- a/codepot/sbin/Makefile.am +++ b/codepot/sbin/Makefile.am @@ -1,4 +1,4 @@ -sbin_SCRIPTS = codepot-user +sbin_SCRIPTS = codepot-user codepot-mon-httpd EXTRA_DIST = $(sbin_SCRIPTS) diff --git a/codepot/sbin/Makefile.in b/codepot/sbin/Makefile.in index 98500d36..2bd5c8c9 100644 --- a/codepot/sbin/Makefile.in +++ b/codepot/sbin/Makefile.in @@ -139,7 +139,7 @@ sharedstatedir = @sharedstatedir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ wwwdir = @wwwdir@ -sbin_SCRIPTS = codepot-user +sbin_SCRIPTS = codepot-user codepot-mon-httpd EXTRA_DIST = $(sbin_SCRIPTS) all: all-am diff --git a/codepot/sbin/codepot-mon-httpd b/codepot/sbin/codepot-mon-httpd new file mode 100644 index 00000000..f6252ffa --- /dev/null +++ b/codepot/sbin/codepot-mon-httpd @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# This is just a sample script for httpd resource monitoring +# While this is inside the codepot distro, it's not supposed +# to be used without consideration of the actual environment. +# + +DAEMON=0 +THRESHOLD=1024 + +if [ "$1" = "-daemon" ] +then + ($0 --daemon /dev/null 2>&1 &) & + #($0 --daemon &) & + exit 0 +elif [ "$1" = "--daemon" ] +then + DAEMON=1 +fi + + +while true +do + sleep 5 + + ps -ylC httpd | awk -vdaemon=$DAEMON -v"self=$0" -vthreshold=$THRESHOLD ' +{ + x += $8; + y += 1; +} +END { + MB = x / 1024; + AVGMB = x / ((y - 1) * 1024); + + if (daemon <= 0) + { + print "Apache Memory Usage (MB): " MB; + print "Average Proccess Size (MB): " AVGMB; + + if (MB > int(threshold)) + { + system ("/etc/init.d/httpd restart"); + } + } + else + { + if (MB > int(threshold)) + { + system (sprintf ("logger -t \"%s\" \"Restarting httpd for excess memory usage [%s/%d]\"", self, MB, threshold)); + system ("/etc/init.d/httpd restart >/dev/null 2>&1