Automating the removal of apache semaphores with ipcs/ipcrm


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Apache Related Information

Automating the removal of apache semaphores with ipcs/ipcrmLast Modified: Dec 17, 2014, 5:07 pm
If you routinely need to remove apache semaphores with the ipcs/ipcrm tool, and if you cannot sort out why they keep building up, then using a cronjob to automatically clear them out if they've piled up may help.

Create a script in:

/etc/cron.hourly/ipcs_check

with the contents:

#!/bin/sh

EMAIL=your@email.com
MAX_SEMAPHORES=15

IPCS=/usr/bin/ipcs
IPCRM=/usr/bin/ipcrm
MAIL=/bin/mail

COUNT=`${IPCS} | grep apache | wc -l`

if [ "$COUNT" -le $MAX_SEMAPHORES ]; then
       #all is well, there are no semaphore build-ups.
       exit 0;
fi

#we have more than MAX_SEMAPHORES, so clear them out and restart Apache.

LIST=/root/sem.txt

${IPCS} | grep apache | awk '{print $2}' > ${LIST}
for i in `cat ${LIST}`; do
{
       ${IPCRM} -s $i;
};
done;

/etc/init.d/httpd restart

TXT="${COUNT} semaphores cleared for apache for `hostname`"
echo "${TXT}" | ${MAIL} -s "${TXT}" ${EMAIL}

exit 1;

and then chmod the script to 755:

chmod 755 /etc/cron.hourly/ipcs_check


Check your /var/log/cron on each hour, to ensure that crond is running it.
If all is well, then there shouldn't be any issues, and the script will exit with a return code of 0.
 
Related Helpfiles
semget: No space left on device

2003 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST