#!/bin/sh
### BEGIN INIT INFO
# Provides:          drbdlinksclean
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Cleans links made by drbdlinks
# Description:       Calls drbdlinks on initial system boot and shutdown to make
#                    sure that any links set up by drbdlinks are cleaned up when
#                    drbd is not running.
### END INIT INFO
#
# Author:	Cyril Bouthors <cyril@bouthors.org>.
#
#
# This script has been converted from the RedHat version provided by
# upstream to Debian

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=drbdlinks
SCRIPTNAME=/etc/init.d/$NAME

if [ ! -x /usr/sbin/drbdlinks ]
then
   echo "No /usr/sbin/drbdlinks file.  Aborting." >&2
   exit 0
fi

if [ ! -f /etc/drbdlinks.conf ]
then
   echo "No /etc/drbdlinks.conf file.  Aborting." >&2
   exit 0
fi


if ! grep -q '^mountpoint(.*)' /etc/drbdlinks.conf
then
    echo 'No mountpoint found in /etc/drbdlinks.conf' >&2
    exit 0
fi

case "$1" in

  start)
	echo -n 'Cleaning up drbdlinks links'
	/usr/sbin/drbdlinks stop
	echo "."
	;;

  stop)
	echo -n 'Cleaning up drbdlinks links'
	/usr/sbin/drbdlinks stop
	echo "."
	;;

  restart|force-reload)
	$0 start
	;;

  status)
	exec /usr/sbin/drbdlinks status
	;;

  *)
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
	exit 1
	;;
esac

exit 0
