#!/bin/bash # restart_apache.sh # # Copyright (C) 2000 Christian Veith # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # you should have received a copy of the GNU General Public License # along with this program (or with Nagios); if not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA #################################### processname=apache2 username=www-data if [ -e /etc/init.d/apache2 ]; then /usr/bin/sudo /etc/init.d/apache2 stop; fi sleep 5 num_processes=$(ps -U $username -C $processname | grep $processname | wc -l) if [[ "$num_processes" -gt "0" ]] then echo "$num_processes Processes found. Killing all I'm the BOFH..." killall $processname sleep 5 fi num_processes=$(ps -U $username -C $processname | grep $processname | wc -l) if [[ "$num_processes" -eq "0" ]] then if [ -e /etc/init.d/apache2 ]; then /usr/bin/sudo /etc/init.d/apache2 start; fi errorcode=$? else echo "Killall not sucessful. Found $num_processes Processes named $processname" errorcode=1 fi if [ $errorcode -eq 0 ]; then echo "DONE!" exit 0 else echo "UNDONE!" exit $errorcode fi