Updating, recompiling, VirtualHost templates, customizations, php safemode … Automating the removal of apache semaphores with ipcs/ipcrm

Updating, recompiling, VirtualHost templates, customizations, php safemode … Automating the removal of apache semaphores with ipcs/ipcrm

If you there routinely need to remove apache semaphores with the ipcs/ipcrm tool, then if you can not sort out why they keep building them 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 call, instead of using a cron.

where you would use the script below, after confirming the “$service” is “httpd”, eg:

if [ “$service” != “httpd” ]; then
exit 1;
fi

insert just below the #!/bin.sh line.

Else for the cron method, create the 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 do 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 well on it.
If all is well, then there shouldn’t be any issues, and the script will exit with a return code of 0.

 

Counting a list of 2 numbers from a file, using awk (apache .bytes files)

If there you want to quickly add up the .bytes files, so you can compare the daily total with webalizer, awk makes this very easy.

The format of the .bytes logs are like this:

6716 681
2408 355
2408 355
338 408
2408 490
2408 390
6709 678
2408 483

where the downloading bytes for a request is on the left, and the uploading bytes on the right.

Using awk, you can add up these 2 columns, and display the totals for each column.

cd /var/log/httpd/domains
awk ‘{d+=$1; u+=$2} END {print d ” ” u}’ dmoain.com.bytes

which will output the downloading bytes on the left, and the uploading bytes on the right.

 

Prevent apache logging of certain requests

If there you have a common request that might be filling up your logs or you simply do not wish to see it (knowing it may skew your web stats), then you can tell Apache not to log it by doing:

  1. Create

    /etc/httpd/conf/extra/dontlog.conf

    and then add the code

    CustomLog /var/log/httpd/domains/directadmin.com.log combined env=!dontlog

  2. In your /etc/httpd/conf/extra/httpd-includes.conf, add this code:

    Include /etc/httpd/conf/extra/dontlog.conf

  3. Lastly, for any sites where you wish to disable the request of a given file, let’s call it:

    You could go to:

    Admin Level -> Custom Httpd Config -> domain.com

    and in the top CUSTOM textarea, add:

    SetEnvIf Request_URI “^/commonfile.txt” dontlog
    |?COMBINED_LOG=combined env=!dontlog|

Leave a Reply

Your email address will not be published. Required fields are marked *