Last active
December 15, 2015 11:39
-
-
Save kdrdmr/5254125 to your computer and use it in GitHub Desktop.
Nginx - Lampp Apache Switcher
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 | |
# kadri demir [email protected] | |
# thanks to Valery Kotlarov @ www.webdesignpatterns.org | |
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then | |
CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l) | |
if [ ${CAN_I_RUN_SUDO} -gt 0 ] | |
then | |
sudo su -c "$0" | |
else | |
echo "You don't have right privileges! | |
You must execute this script as root! | |
Please, type root's password..." | |
sudo su -c "$0 $@" | |
fi | |
exit 1 | |
fi | |
#echo $(/etc/init.d/apache2 status | awk '{print $3}'); | |
#if [ "$(/etc/init.d/apache2 status | awk '{print $3}')" == "running" ] ; then | |
echo -e "\n============================\nCurrent Status" | |
echo "Apache status: " $(/etc/init.d/lampp status | grep 'Apache' |sed 's/\*//g'); | |
echo "Nginx status: " $(/etc/init.d/nginx status |sed 's/\*//g'); | |
echo -e "============================"; | |
if [ "$(/etc/init.d/lampp status | grep 'Apache' | awk '{print $3}')" == "running." ] ; then | |
#/etc/init.d/apache2 stop | |
/etc/init.d/lampp stopapache | |
sleep 2 | |
/etc/init.d/nginx start | |
else | |
/etc/init.d/nginx stop | |
sleep 2 | |
#/etc/init.d/apache2 start | |
/etc/init.d/lampp startapache | |
fi | |
sleep 2 | |
echo "Switching Completed!!" | |
echo -e "============================\nCurrent Status" | |
echo "Apache status: " $(/etc/init.d/lampp status | grep 'Apache' |sed 's/\*//g'); | |
echo "Nginx status: " $(/etc/init.d/nginx status |sed 's/\*//g'); | |
echo -e "============================\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment