| 1 | This is a script to check if the apache !MaxClientsVhost limit has been hit, it's used on PuffinServer and a email is sent to root every day when the !MaxClientsVhost limit is reached. |
| 2 | |
| 3 | {{{ |
| 4 | #!/bin/bash |
| 5 | |
| 6 | # This script checks for the Apache MaxClientsVhost limit being hit |
| 7 | # It's run via /etc/logrrotate.d/apache2 just before thenlogs are rotated |
| 8 | # If an email address is passed to the script then the results will be sent |
| 9 | # out by email. |
| 10 | |
| 11 | # Location of the apache log file we are checking |
| 12 | LOGFILE=/var/log/apache2/error.log |
| 13 | |
| 14 | # Name of the server this is running on |
| 15 | HOSTNAME=$(hostname -f) |
| 16 | |
| 17 | # The lines are are grepping for |
| 18 | GREP=$(grep MaxClientsVhost $LOGFILE | uniq -u) |
| 19 | |
| 20 | # The subject line of the email |
| 21 | SUBJECT="MaxClientsVhost limit hit on $HOSTNAME" |
| 22 | |
| 23 | # Optional email address |
| 24 | EMAIL=$1 |
| 25 | |
| 26 | # check that the script is being run by root |
| 27 | if [[ "$(id -u)" != "0" ]] ; then |
| 28 | echo "You must run $0 as root or via sudo" |
| 29 | exit 2 |
| 30 | fi |
| 31 | |
| 32 | # Check to see if any errors were found |
| 33 | if [[ $GREP ]]; then |
| 34 | # Check for a email address |
| 35 | if [[ $1 ]]; then |
| 36 | echo "$GREP" | mutt -s "$SUBJECT" $EMAIL |
| 37 | # Display the results of the grep |
| 38 | else [[ ! $1 ]] |
| 39 | echo "Supply a email address on the command line to send the following results by email" |
| 40 | echo "" |
| 41 | echo "$GREP" |
| 42 | fi |
| 43 | else |
| 44 | # We don't want any output if an email address is supplied |
| 45 | if [[ ! $EMAIL ]] ; then |
| 46 | echo "No recent errors were found" |
| 47 | fi |
| 48 | fi |
| 49 | }}} |
| 50 | |
| 51 | The script is called via {{{/etc/logrotate.d/apache2}}} which contains: |
| 52 | |
| 53 | {{{ |
| 54 | /var/log/apache2/*.log { |
| 55 | daily |
| 56 | missingok |
| 57 | rotate 28 |
| 58 | compress |
| 59 | delaycompress |
| 60 | notifempty |
| 61 | create 640 root adm |
| 62 | sharedscripts |
| 63 | prerotate |
| 64 | /usr/local/webarch/bin/maxclients root@localhost |
| 65 | endscript |
| 66 | postrotate |
| 67 | /etc/init.d/apache2 reload > /dev/null |
| 68 | endscript |
| 69 | } |
| 70 | }}} |