#!/bin/bash
#
# chkconfig: 2345 98 02
# description: Hinemos Manager

# Copyright (C) 2013 NTT DATA Corporation
# 
# 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.
# 
# 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

# Source function library.
. /etc/rc.d/init.d/functions

# bash configuration
. /opt/hinemos/hinemos.cfg
. /opt/hinemos/sbin/hinemos_utility.sh

export PROG=`basename $0`
DIR=`dirname $0`
USER=`/usr/bin/whoami`
HOST=`hostname`

########################################
#  Local Variable
########################################

########################################
#  Local Message
########################################

# INFO
#MSG_I001="xxx"

# WARN
#MSG_W001="xxx"

# ERROR
MSG_E001="usage : ${PROG} [start|stop|status|restart]"

########################################
# Function
########################################

function hinemos_manager_start() {
	
	local RET=0
	/opt/hinemos/bin/hinemos_start.sh -W
	RET=$?
	if [ ${RET} -eq 0 ]
	then
		echo_success
		echo
	else
		echo_failure
		echo
		return 1
	fi
	return 0
}

function hinemos_manager_stop() {
	
	local RET=0
	/opt/hinemos/bin/hinemos_stop.sh
	RET=$?
	if [ ${RET} -eq 0 ]
	then
		echo_success
		echo
	else
		echo_failure
		echo
		return 1
	fi
	
	return 0
}

function hinemos_manager_status() {
	
	local FUNC_RET=0
	
	# Check ALL
	CheckHinemosManagerStatus
	FUNC_RET=$?
	
	return ${FUNC_RET}
}

########################################
# SHELL
########################################

case "$1" in
	start)
		hinemos_manager_start
		RET=$?
		;;
	stop)
		hinemos_manager_stop
		RET=$?
		;;
	status)
		hinemos_manager_status
		RET=$?
		;;
	restart)
		hinemos_manager_stop && hinemos_manager_start
		RET=$?
		;;
	*)
		echo "${MSG_E001}"
		RET=1
esac

exit ${RET}
