summaryrefslogtreecommitdiff
path: root/community/drbd/drbd.rc
blob: 893ce3e208e757b60961836df8b7cc2ac4b748b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Written by Sébastien Luttringer

. /etc/rc.conf
. /etc/rc.d/functions

DRBDADM='/usr/sbin/drbdadm'
PROC_DRBD='/proc/drbd'

check_config() {
  # check if module is loaded
  if [[ ! -e $PROC_DRBD ]]; then
    echo "Missing $PROC_DRBD. Try to load drbd module!"
    stat_fail
    exit 1
  fi
  # check if config is correct
  if ! $DRBDADM dump &>/dev/null; then
      echo 'Invalid configuration'
      stat_fail
      exit 1
  fi
}

case "$1" in
  start)
    stat_busy 'Starting DRBD resources'
    # check module and config
    check_config
    # load config
    $DRBDADM adjust all 2>/dev/null || { stat_fail; exit 1; }
    # User interruptible version of wait-connect all
    $DRBDADM wait-con-int 2>/dev/null || { stat_fail; exit 1; }
    # Become primary if configured
    $DRBDADM sh-b-pri all 2>/dev/nul l|| { stat_fail; exit 1; }
    add_daemon drbd
    stat_done
    ;;
  stop)
    stat_busy 'Stopping DRBD resources'
    # check module and config
    check_config
    # disconnect and detach all resources
    $DRBDADM down all 2>/dev/null || { stat_fail; exit 1; }
    rm_daemon drbd
    stat_done
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"
esac

exit 0

# vim:set ts=2 sw=2 ft=sh et: