
########################################################################
# MuGLIn - MuGLIn GNU/Linux Installation		               #
#                                                                      #
# Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>       #
# Copyricht (C) 2010 Srdjan Markovic <smark2ki@htl.moedling.at>        #
#                                                                      #
# This file is part of MuGLIn source code.                             #
#                                                                      #
# MuGLIn is free software: you can redistribute it and/or modify       #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or    #
# (at your option) any later version.                                  #
#                                                                      #
# MuGLIn is distributed in the hope that it will be useful,            #
# but WITHOUT ANY WARRANTY; without even the implied warranty of       #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        #
# GNU General Public License for more details.                         #
#                                                                      #
# You should have received a copy of the GNU General Public License    #
# along with MuGLIn. If not, see <http://www.gnu.org/licenses/>.       #
########################################################################

SITE_DIR="/etc/apache2/sites-enabled/"

case "$1" in
	start)
		if [ -e $SITE_DIR/$SITE ]; then
			echo "$TITLE is already active, you may need to restart Apache"
		fi
		echo -n "Starting $TITLE..."
		a2ensite $SITE > /dev/null 2>&1
		/etc/init.d/apache2 reload > /dev/null 2>&1
		if [ "$?" = "0" ]; then
			echo "done"
		else
			echo "failed"
		fi
	;;
	stop)
		if [ ! -e $SITE_DIR/$SITE ]; then
			echo "$TITLE is already deactivated, you may need to restart Apache"
			exit
		fi
		echo -n "Shutting down $TITLE..."
		a2dissite $SITE > /dev/null 2>&1
		/etc/init.d/apache2 reload > /dev/null 2>&1
		if [ "$?" = "0" ]; then
			echo "done"
		else
			echo "failed"
		fi
	;;
	# do we realy need a restart?
	restart)
		$0 stop
		$0 start
	;;
	status)
		ok=0
		echo -n "$TITLE: "
		if [ -e $SITE_DIR/$SITE ]; then	
			echo "enabled."
			ok=1
		else
			echo "disabled."
		fi
		echo -n "Network-port (Apache/$PORT): "
		if [ "`netstat -l -p -n | grep apache2 | grep 443`" = "" ];then
			echo "closed."
			ok=0
		else
			echo "open."
		fi
		exit $ok
	;;
esac