#!/bin/sh
# Fixes apache ipcs problem.
# Written by hip0. Licensed under the general public license 2.0 and above.
verbose=0;
ipc_state=`ipcs -s | grep -v "\-" | grep -v "key" | wc -l | awk '{ print $1 }'`;


if [ "$ipc_state" -gt 6 ]; then

 if [ "$verbose" -eq 1 ]; then
  echo "apache ipcs problem. Fixing ...";
 fi
su httpd -c "ipcs -s | grep httpd |  perl -e 'while () { @a=split(/\s+/); print `ipcrm $a[1]`}'";
/usr/local/apache2/bin/apachectl -k restart
 exit 0;

fi

if [ "$ipc_state" -lt 6 ] || [ "$ipc_state" -eq 6 ]; then

 if [ "$verbose" -eq 1 ]; then
  echo "Apache is Okay. Nothing to be done";
 fi
exit 0;

fi

