Last active
August 29, 2015 14:00
-
-
Save sankalp-khare/11306259 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o errexit | |
# toggles between httpd 2.2.x and 2.4.x | |
# 2.2.x packages | |
# httpd.x86_64 2.2.26-1.1.amzn1 @amzn-updates | |
# httpd-devel.x86_64 2.2.26-1.1.amzn1 @amzn-updates | |
# httpd-tools.x86_64 2.2.26-1.1.amzn1 @amzn-updates | |
# 2.4.x packages | |
# httpd24.x86_64 : Apache HTTP Server | |
# httpd24-devel.x86_64 : Development interfaces for the Apache HTTP server | |
# httpd24-tools.x86_64 : Tools for use with the Apache HTTP Server | |
# === Colour Definitions === | |
red='\e[0;31m' | |
green='\e[0;32m' | |
purple='\e[0;35m' | |
orange='\e[0;33m' | |
# No Color, i.e. turn off color | |
nc='\e[0m' | |
# Fail eagerly if run as root. | |
# from https://gist.github.com/rehevkor5/5145245 | |
if [[ $EUID -eq 0 ]]; then | |
echo -e "${red}This script must be run as ec2-user.${nc}" 1>&2 | |
exit 1 | |
fi | |
if [ -z "$1" ] | |
then | |
echo -e "${orange}[usage]${nc} ${0} staging ${red}OR${nc} ${0} production" | |
exit 2 | |
else | |
if [ $1 = "staging" ] | |
then | |
MACHINE_ENV=staging | |
elif [ $1 = "production" ] | |
then | |
MACHINE_ENV=production | |
else | |
echo -e "${orange}[usage]${nc} ${0} staging ${red}OR${nc} ${0} production" | |
exit 3 | |
fi | |
fi | |
# directory where httpd config is stored | |
CONF_STORE="./${MACHINE_ENV}/mobolt-httpd-config" | |
# check whether apache 2.4.x is present | |
# [begin] block where errors do not result in an exit | |
set +o errexit | |
rpm -qi httpd24 &>/dev/null | |
# capture the return value of rpm, else it'll be overwritten when set is | |
# called and returns success | |
RV=$? | |
set -o errexit | |
# [end] block | |
# if httpd24 is found | |
if (( ${RV} == 0 )) | |
then | |
# remove httpd 2.4.x | |
echo -e "${orange}[INFO]${green} httpd 2.4.x found${nc}. ${red}Erasing...${nc}" | |
# sudo service httpd stop | |
sudo yum erase httpd24{,-tools,-devel} | |
# install httpd 2.2.x | |
echo -e "${orange}[INFO]${green} Installing httpd 2.2.x...${nc}" | |
sudo yum install httpd{,-tools,-devel} | |
# rebuild passenger module | |
echo -e "${orange}[INFO]${green} Building passenger module...${nc}" | |
# remove the existing config which references the existing (now useless) | |
# passenger module, since the compilation process checks for a sane httpd | |
# config | |
sudo rm -fv /etc/httpd/conf.d/{app,passenger}.conf | |
# initiate build process | |
passenger-install-apache2-module | |
# install mobolt config (app.conf, passenger.conf) for apache 2.2.x | |
echo -e "${orange}[INFO]${green} Installing MoBolt configuration...${nc}" | |
sudo cp -v "${CONF_STORE}"/2.2.x/conf.d/{app,passenger}.conf /etc/httpd/conf.d/ | |
# bring the apache server up again | |
sudo service httpd restart | |
exit 0 # only one version toggle required. | |
fi | |
# check whether apache 2.2.x is present | |
# [begin] block where errors do not result in an exit | |
set +o errexit | |
rpm -qi httpd &>/dev/null | |
# capture the return value of rpm, else it'll be overwritten when set is | |
# called and returns success | |
RV=$? | |
set -o errexit | |
# [end] block | |
# if httpd is found | |
if (( ${RV} == 0 )) | |
then | |
# remove httpd 2.2.x | |
echo -e "${orange}[INFO]${green} httpd 2.2.x found${nc}. ${red}Erasing...${nc}" | |
# sudo service httpd stop | |
sudo yum erase httpd{,-tools,-devel} | |
# install httpd 2.4.x | |
echo -e "${orange}[INFO]${green} Installing httpd 2.4.x...${nc}" | |
sudo yum install httpd24{,-tools,-devel} | |
# rebuild passenger module | |
echo -e "${orange}[INFO]${green} Building passenger module...${nc}" | |
# remove the existing config which references the existing (now useless) | |
# passenger module, since the compilation process checks for a sane httpd | |
# config | |
sudo rm -fv /etc/httpd/conf.d/{app,passenger}.conf | |
# initiate build process | |
passenger-install-apache2-module | |
# install mobolt config (app.conf, passenger.conf) for apache 2.4.x | |
echo -e "${orange}[INFO]${green} Installing MoBolt configuration...${nc}" | |
sudo cp -v "${CONF_STORE}"/2.4.x/conf.d/{app,passenger}.conf /etc/httpd/conf.d/ | |
# bring the apache server up again | |
sudo service httpd restart | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment