Add to Favourites Add to Favourites    Print this Article Print this Article

Automating the removal of apache semaphores with ipcs/ipcrm

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.

UPDATE: DirectAdmin 1.53.0+ now has a hook script which can be called, instead of using a cron.  This should provide faster reaction times for a downed service:
where you'd use the script below, after confirming the "$service" is "httpd", eg:

if [ "$service" != "httpd" ]; then
       exit 1;

inserted just below the #!/ line.

Else for the cron method, create the script in:


with the contents:



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

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

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


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

/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.

Was this answer helpful?

Also Read