#!/bin/sh
#
# Corosync daemon init script for Red Hat Linux and compatibles.
#
# chkconfig: - 20 20
# processname:  corosync
# pidfile:      /var/run/corosync.pid
# description:  OpenAIS
### BEGIN INIT INFO
# Provides:             corosync
# Required-Start:       $network
# Required-Stop:        $network
# Default-Start:
# Default-Stop:
# Short-Description:    Starts and stops corosync
# Description:          Starts and stops OpenAIS corosync
### END INIT INFO

# 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() {
    gprintf "Starting OpenAIS (%s): " "$prog"
    export COROSYNC_DEFAULT_CONFIG_IFACE="openaisserviceenable:openaisparser"
    daemon $exec
    retval=$?
    [ "$retval" -eq 0 ] && touch "$lockfile"
    echo
    return $retval
}

stop() {
    gprintf "Stopping OpenAIS (%s): " "$prog"
    killproc $prog
    retval=$?
    [ "$retval" -eq 0 ] && rm -f "$lockfile"
    echo
    return $retval
}

restart() {
    stop
    start
}

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