#!/bin/bash
#
# 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.
#
#
# qpidd        Startup script for the Qpid messaging daemon.
#
### BEGIN INIT INFO
# Provides: qpidd
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start or stop qpidd
# Description: Qpidd is an AMQP broker. It receives, stores, routes and forwards messages using the AMQP protcol.
### END INIT INFO

DAEMON="qpidd"

start ()
{
    echo -n "Starting ${DAEMON}..."
    if pidof ${DAEMON} > /dev/null; then
        echo "already running."
        exit 0
    fi
    start-stop-daemon --start --quiet --background --exec ${DAEMON}
    if [ $? -eq 0 ]; then
        echo "done."
    else
        echo "failed."
    fi
}

stop ()
{
    echo "Stopping ${DAEMON}..."
    if ! pidof ${DAEMON} >/dev/null; then
        echo "not running."
        exit 0
    fi
    start-stop-daemon --stop --quiet --exec ${DAEMON}
    if [ $? -eq 0 ]; then
        echo "done."
    else
        echo "failed."
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart|force-reload)
        stop
        start
        ;;
    *)
        echo "Usage: $0 {start|stop|force-reload|restart}"
        exit 1
        ;;
esac

exit 0
