#!/bin/bash
#
# Run-level Startup script for Apache Knox Gateway
#
# chkconfig: 345 85 15
# description: Startup/Shutdown Apache Knox Gateway

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# /etc/init.d/knox

KNOX_HOME="/usr/hdp/current/knox-server"
KNOX_USER="knox"

# if the executables do not exist -- display error

if [ ! -f $KNOX_HOME/bin/gateway.sh -o ! -d $KNOX_HOME ]
then
        echo "Apache Knox Gateway startup: cannot start"
        exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
    start)
        echo -n "Starting Apache Knox Gateway: "
        su - $KNOX_USER -c "$KNOX_HOME/bin/gateway.sh start"
        ;;
    stop)
        echo -n "Shutdown Apache Knox Gateway: "
        su - $KNOX_USER -c "$KNOX_HOME/bin/gateway.sh stop"
        ;;
    status)
        echo -n "Checking Apache Knox Gateway Status: "
        su - $KNOX_USER -c "$KNOX_HOME/bin/gateway.sh status"
        ;;
    reload|restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|status|restart|reload"
        exit 1
esac

exit 0
