games-board/freedoko: Drop old
[gentoo.git] / sys-cluster / drbd / files / drbd-8.0.rc
1 #!/sbin/openrc-run
2 # Copyright 1999-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License, v2 or later
4
5 extra_started_commands="reload"
6
7 depend() {
8         use logger
9         need net
10         before heartbeat
11         after sshd
12 }
13
14 DEFAULTFILE="/etc/conf.d/drbd"
15 DRBDADM="/sbin/drbdadm"
16 PROC_DRBD="/proc/drbd"
17 MODPROBE="/sbin/modprobe"
18 RMMOD="/sbin/rmmod"
19 UDEV_TIMEOUT=10
20 ADD_MOD_PARAM=""
21
22 if [ -f $DEFAULTFILE ]; then
23   . $DEFAULTFILE
24 fi
25
26 # Just in case drbdadm want to display any errors in the configuration
27 # file, or we need to ask the user about registering this installation
28 # at http://usage.drbd.org, we call drbdadm here without any IO
29 # redirection.
30 $DRBDADM sh-nop
31
32 assure_module_is_loaded() {
33         [ -e "$PROC_DRBD" ] && return
34         ebegin "Loading drbd module"
35         ret=0
36
37         $MODPROBE -s drbd `$DRBDADM sh-mod-parms` $ADD_MOD_PARAM || ret=20
38         eend $ret
39         return $ret
40 }
41
42 adjust_with_progress() {
43         IFS_O=$IFS
44         NEWLINE='
45 '
46         IFS=$NEWLINE
47         local D=0
48         local S=0
49         local N=0
50
51         einfon "Setting drbd parameters "
52         COMMANDS=`$DRBDADM -d adjust all` || { 
53                 eend 20 "Error executing drbdadm"
54                 return 20 
55         }
56         echo -n "[ "
57         
58         for CMD in $COMMANDS; do
59                 if echo $CMD | grep -q disk; then echo -n "d$D "; D=$(( D+1 ));
60                 elif echo $CMD | grep -q syncer; then echo -n "s$S "; S=$(( S+1 ));
61                 elif echo $CMD | grep -q net; then echo -n "n$N "; N=$(( N+1 ));
62                 else echo echo -n ".. ";
63                 fi
64                 IFS=$IFS_O
65                 eval $CMD || {
66                         echo 
67                         eend 20 "cmd $CMD failed!"
68                         return 20
69                 }
70                 IFS=$NEWLINE
71         done
72         echo "]"
73         eend 0
74         
75         IFS=$IFS_O
76 }
77
78 start() {
79         einfo "Starting DRBD resources:"
80         eindent
81         assure_module_is_loaded || return $?
82         adjust_with_progress || return $?
83
84         # make sure udev has time to create the device files
85         ebegin "Waiting for udev device creation ..."
86         for RESOURCE in `$DRBDADM sh-resources`; do
87                 for DEVICE in `$DRBDADM sh-dev $RESOURCE`; do
88                         UDEV_TIMEOUT_LOCAL=$UDEV_TIMEOUT
89                         while [ ! -e $DEVICE ] && [ $UDEV_TIMEOUT_LOCAL -gt 0 ] ; do
90                                 sleep 1
91                                 UDEV_TIMEOUT_LOCAL=$(( $UDEV_TIMEOUT_LOCAL-1 ))
92                         done
93                 done
94         done
95         eend 0
96
97         einfon "Waiting for connection "
98         $DRBDADM wait-con-int
99         ret=$?
100         echo
101
102         sleep 5
103         
104         einfon "Become primary if configured "
105         $DRBDADM sh-b-pri all
106         echo
107
108         eend $ret
109         return $ret
110 }
111
112 stop() {
113         ebegin "Stopping all DRBD resources"
114         
115         # Check for mounted drbd devices
116         if ! grep -q '^/dev/drbd' /proc/mounts &>/dev/null; then
117                 if [ -e ${PROC_DRBD} ]; then
118                         ${DRBDADM} down all
119                         ret=$?
120                         sleep 3
121                         if [ -e /proc/modules ] && grep -q '^drbd' /proc/modules ; then
122                               ${RMMOD} drbd
123                 fi
124                 fi
125                 eend $ret
126                 return $ret
127         else
128                 einfo "drbd devices mounted, please umount them before trying to stop drbd!"
129                 eend 1
130                 return 1
131         fi
132 }
133
134 status() {
135         # NEEDS to be heartbeat friendly...
136         # so: put some "OK" in the output.
137         
138         if [ -e $PROC_DRBD ]; then
139                 ret=0
140                 ebegin "drbd driver loaded OK; device status:"
141                 eend $ret
142                 cat $PROC_DRBD
143         else
144                 ebegin "drbd not loaded"
145                 ret=3
146                 eend $ret
147         fi
148         return $ret
149 }
150
151 reload() {
152         ebegin "Reloading DRBD"
153         ${DRBDADM} adjust all
154         ret=$?
155         eend $ret
156         return $ret
157 }