Skip to content

Instantly share code, notes, and snippets.

@miglen
Created September 4, 2014 06:29
Show Gist options
  • Save miglen/63fbb3728818a73e859b to your computer and use it in GitHub Desktop.
Save miglen/63fbb3728818a73e859b to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# @description Script used to switch between prefork and worker mpm
# @author Miglen Evlogiev <miglen@hp.com>
# @version 0.1
# @date 3/9/14 18:03 PM CET
# @usage apachempm.sh <mpm_method> or status
# <mpm_method> = worker or prefork
# you may add it to your .bash_profile as alias apachempm="/path/to/apachempm.sh"
#
currentmpm=`apachectl -V | grep "Server MPM" | tr -s " " | cut -d" " -f 3`
RETVAL=1
status(){
currentmpm=`apachectl -V | grep "Server MPM" | tr -s " " | cut -d" " -f 3`
echo -e "\t\tCurrent Apache MPM \e[93m`tput bold`${currentmpm}`tput sgr0`\e[39m"
}
worker(){
echo -e "\t\tSwitching to Worker MPM "
if [ $currentmpm == "Prefork" ]
then sed -i 's/#HTTPD=/HTTPD=/g' /etc/sysconfig/httpd
apachectl -k graceful
echo -e "\t\tRestarting Apache web server gracefully"
fi
status
}
prefork(){
echo -e "\t\tSwitching to Prefork MPM "
if [ $currentmpm != "Prefork" ]
then sed -i 's/HTTPD=/#HTTPD=/g' /etc/sysconfig/httpd
apachectl -k graceful
echo -e "\t\tRestarting Apache web server gracefully"
fi
status
}
case "$1" in
status)
status
;;
worker)
worker
;;
prefork)
prefork
;;
*)
echo -e "\t\tUsage: apachempm {worker|prefork|status}\n"
RETVAL=2
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment