#!/bin/sh
# Clean Apache semaphors if Apache Webserver on Debian Linux reports no space left on device in 
# /var/log/apache2/error.log 
# even though  there is plenty of space 
# Error that indicates about the semapor problems in /var/log/apache23/error.log
# [Sun Oct 15 06:40:26 2017] [emerg] (28)No space left on device: Couldn't create accept lock (/var/lock/apache2/accept.lock.16111) (5)
#
echo "Output of current Apache semaphors, many hanging semaphors is bad ...";

ipcs -s
if [[ $(ipcs -s |wc -l) -gt 10 ]]; then
for i in `ipcs -s | awk '/www-data/ {print $2}'`; do (ipcrm -s $i); done
echo '-----------------------------------------------------------------'
echo "Clearing Unattached semaphors with ipcs to make Apache work again";
echo '------------------------------------------------------------------';
echo "Now start /restart Apache again with /etc/init.d/apache2 start";
else
echo "Apache Semaphors seems fine";
fi
