#!/bin/bash
# 
# ***** BEGIN LICENSE BLOCK *****
# Zimbra Collaboration Suite Server
# Copyright (C) 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc.
#
# This program 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,
# version 2 of the License.
#
# This program 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 this program.
# If not, see <https://www.gnu.org/licenses/>.
# ***** END LICENSE BLOCK *****
# 

BASE=/opt/zimbra
SCRIPTS="zmamavisdctl"

source /opt/zimbra/.bashrc

case "$1" in 
	start)
		for i in $SCRIPTS; do
			/opt/zimbra/bin/$i start $2
		done
	;;
	stop)
		for i in $SCRIPTS; do
			/opt/zimbra/bin/$i stop
		done
	;;
	reload|restart)
		for i in $SCRIPTS; do
			/opt/zimbra/bin/$i $1
		done
	;;
	status)
		STATUS=0
		for i in $SCRIPTS; do
			/opt/zimbra/bin/$i status
			R=$?
			if [ $R -ne "0" ]; then
				echo "$i is not running"
				STATUS=$R
			fi
		done
		exit $STATUS
	;;
	*)
		echo "$0 start|stop|restart|reload|status"
		exit 1
	;;
esac
