#!/bin/sh
#
# Corosync daemon init script for Red Hat Linux and compatibles.
#
# chkconfig: - 20 20
# processname:  corosync
# pidfile:      /var/run/corosync.pid
# description:  Corosync Cluster Engine

# Source function library
. /etc/rc.d/init.d/functions

prog="corosync"
exec="/usr/sbin/corosync"
lockfile="/var/lock/subsys/corosync"

[ -x "$exec" ] || exit 0

start() {
    echo -n $"Starting Corosync Cluster Engine ($prog): "
    daemon $exec
    retval=$?
    [ "$retval" -eq 0 ] && touch "$lockfile"
    echo
    return $retval
}

stop() {
    echo -n $"Stopping Corosync Cluster Engine ($prog): "
    # If no signal is specified, -TERM is used but _also_ -KILL 3s later
    # This is far too aggressive for a cluster resource manager running on top of Corosync
    killproc $prog -TERM
    echo

    echo -n $"Waiting for services to unload:"
    while
        pidofproc $prog > /dev/null 2>&1
    do
        sleep 2
    done

    success $"$base shutdown"
    echo

    rm -f "$lockfile"
    return 0
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    reload|force-reload)
        restart
        ;;
    condrestart|try-restart)
        [ ! -f "$lockfile" ] || restart
        ;;
    status)
        status $prog
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|try-restart|condrestart|reload|force-reload|status}"
        exit 2
esac
