#!/bin/sh

### BEGIN INIT INFO
# Provides:          keystone
# Short-Description: OpenStack Identity Service
### END INIT INFO

DESC="keystone"
DAEMON="/usr/bin/keystone-all"
PIDFILE="/var/run/keystone-all.pid"

start ()
{
    if [ -e $PIDFILE ]; then
        PIDDIR=/proc/$(cat $PIDFILE)
        if [ -d ${PIDDIR} ]; then
            echo "$DESC already running."
            exit 1
        else
            echo "Removing stale PID file $PIDFILE"
            rm -f $PIDFILE
        fi
    fi

    echo -n "Starting $DESC..."

    start-stop-daemon --start --quiet --background \
        --pidfile ${PIDFILE} --make-pidfile --exec ${DAEMON}

    if [ $? -eq 0 ]; then
        echo "done."
    else
        echo "failed."
    fi
}

stop ()
{
    echo -n "Stopping $DESC..."
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
    if [ $? -eq 0 ]; then
        echo "done."
    else
        echo "failed."
    fi
    rm -f $PIDFILE
}

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
