Last active
December 28, 2015 03:38
-
-
Save jaygooby/7436045 to your computer and use it in GitHub Desktop.
Need to toggle between nginx and Apache on your development machine?
This file contains 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 | |
# | |
# Needs to be run as sudo toggle-port-80 | |
# | |
# because port 80 is a privileged port | |
# | |
# Jay Caines-Gooby | |
# jay@gooby.org | |
# @jaygooby | |
NGINX=/usr/local/sbin/nginx | |
APACHE=/usr/sbin/apachectl | |
ps cax | egrep 'nginx|httpd' > /dev/null | |
if [ $? -ne 0 ]; then | |
# normally I want nginx started | |
echo "Starting nginx" | |
DAEMON=$NGINX | |
else | |
# if Apache's running stop it and start nginx | |
# or if nginx is running, stop it and start Apache | |
ps cax | egrep 'httpd' > /dev/null | |
if [ $? == 0 ]; then | |
echo "Stopping Apache, starting nginx" | |
$APACHE stop | |
DAEMON=$NGINX | |
else | |
echo "Stopping nginx, starting Apache" | |
$NGINX -s stop | |
DAEMON="$APACHE start" | |
fi | |
fi | |
# give the old daemon a chance to shutdown | |
sleep 3 | |
$DAEMON |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment