Skip to content

Instantly share code, notes, and snippets.

@jaygooby
Last active December 28, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaygooby/7436045 to your computer and use it in GitHub Desktop.
Save jaygooby/7436045 to your computer and use it in GitHub Desktop.
Need to toggle between nginx and Apache on your development machine?
#!/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