#!/bin/bash
#/**
# * Copyright 2013 NGDATA nv
# *cd bi
# * Copyright 2007 The Apache Software Foundation
# *
# * 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/rc.d/init.d/hbase-indexer
#
#       Startup/shutdown script for the hbase-indexer service
#
# <tags -- see below for tag definitions.  *Every line* from the top
#  of the file to the end of the tags section must begin with a #
#  character.  After the tags section, there should be a blank line.
#  This keeps normal comments in the rest of the file from being
#  mistaken for tags, should they happen to fit the pattern.>
### BEGIN INIT INFO
# Provides:          hbase-indexer
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: HBase-indexer service script
# Description:       The Hbase indexer
### END INIT INFO

# Source function library.
. /etc/init.d/functions
# Hbase indexer settings
. /etc/hbase-indexer/conf/hbase-indexer-env.sh

HBASE_INDEXER_HOME=/usr/lib/hbase-indexer
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Indexer service for hbase"
NAME=hbase-indexer
DAEMON=${HBASE_INDEXER_HOME}/bin/$NAME
export HBASE_INDEXER_CONF_DIR=/etc/hbase-indexer/conf
DAEMON_ARGS="daemon"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
lockfile=/var/lock/subsys/${NAME}

start() {
        echo -n "Starting ${NAME}: "
        daemon ${DAEMON} ${DAEMON_ARGS}
        RETVAL=$?
        [ $RETVAL = 0 ] && touch $lockfile
        return $RETVAL
}

stop() {
        echo -n "Shutting down ${NAME}: "
        killproc $DAEMON
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f $lockfile
        return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status -l $(basename $lockfile) $DAEMON
        RETVAL=$?
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: ${NAME} {start|stop|status|restart"
        exit 1
        ;;
esac
exit $?
