#! /bin/bash

# catch mis-use right here at the start
if [  "$1" != "start"  -a  "$1" != "stop"  -a  "$1" != "status" -a "$1" != "restart" ]; then
    echo "Usage: $0 {start|stop|status|restart}"
    exit 1
fi

test -z "$HOME" || exec -c $0 $@ # execute always in clear environment

. /usr/lib/orarun/common.sh
ora_environment

if [ -z "$ORACLE_HOME_LISTENER" ]; then
	echo "Using ORACLE_HOME_LISTENER from ORACLE_HOME"
        ORACLE_HOME_LISTENER=$ORACLE_HOME
fi

echo "ORACLE_HOME_LISTENER is $ORACLE_HOME_LISTENER"

# First reset status of this service
rc=0

# Here we finally get to do the real work.
case "$1" in
	start)
		echo -n "Starting Oracle Listener..."
		ORACLE_HOME=$ORACLE_HOME_LISTENER
		$ORACLE_HOME_LISTENER/bin/lsnrctl start > /dev/null
		rc=$?
	;;
	stop)
		echo "Shutting down Oracle listener..."	
		ORACLE_HOME=$ORACLE_HOME_LISTENER
		$ORACLE_HOME_LISTENER/bin/lsnrctl stop > /dev/null
		rc=$?
	;;
esac

exit $rc
