Created
July 6, 2012 22:05
-
-
Save ljfauscett/3063007 to your computer and use it in GitHub Desktop.
nginx enable/disable sites
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 | |
SITES_AVAILABLE_DIR=/etc/nginx/sites-available | |
SITES_ENABLED_DIR=/etc/nginx/sites-enabled | |
function print_usage() { | |
echo "nginx-site -e <site name> to enable" | |
echo "nginx-site -d <site name> to disable" | |
} | |
if [ $# -ne 2 ]; then | |
print_usage | |
exit 1 | |
elif [ $1 != "-e" ] && [ $1 != "-d" ]; then | |
print_usage | |
exit 1 | |
else | |
SITE_AVAILABLE="$SITES_AVAILABLE_DIR/$2" | |
SITE_ENABLED="$SITES_ENABLED_DIR/$2" | |
fi | |
if [ $1 == "-e" ]; then | |
if [ ! -e $SITE_AVAILABLE ]; then | |
echo "$2 does not exist." | |
exit 0 | |
fi | |
if [ -h $SITE_ENABLED ]; then | |
echo "$2 is already enabled." | |
exit 0 | |
else | |
ln -s $SITE_AVAILABLE $SITE_ENABLED | |
echo "$2 has been enabled. Restart nginx." | |
fi | |
fi | |
if [ $1 == "-d" ]; then | |
if [ ! -h $SITE_ENABLED ]; then | |
echo "$2 is not enabled." | |
exit 0 | |
else | |
rm $SITE_ENABLED | |
echo "$2 has been disabled. Restart nginx." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment