]> sourceware.org Git - lvm2.git/blame - scripts/clvmd_init_red_hat.in
Refer to details of snapshot of raid problem.
[lvm2.git] / scripts / clvmd_init_red_hat.in
CommitLineData
edd86b1f
AK
1#!/bin/bash
2#
630e13ed
FDN
3# clvmd - Clustered LVM Daemon init script
4#
edd86b1f 5# chkconfig: - 24 76
630e13ed 6# description: Cluster daemon for userland logical volume management tools.
edd86b1f
AK
7#
8# For Red-Hat-based distributions such as Fedora, RHEL, CentOS.
630e13ed 9#
edd86b1f 10### BEGIN INIT INFO
630e13ed 11# Provides: clvmd
34b6075d
FDN
12# Required-Start: $local_fs@CLVMD_CMANAGERS@
13# Required-Stop: $local_fs@CLVMD_CMANAGERS@
630e13ed
FDN
14# Short-Description: This service is Clusterd LVM Daemon.
15# Description: Cluster daemon for userland logical volume management tools.
edd86b1f
AK
16### END INIT INFO
17
630e13ed 18. /etc/rc.d/init.d/functions
edd86b1f
AK
19
20DAEMON=clvmd
21
22exec_prefix=@exec_prefix@
23sbindir=@sbindir@
24
630e13ed
FDN
25lvm_vgchange=${sbindir}/vgchange
26lvm_vgdisplay=${sbindir}/vgdisplay
27lvm_vgscan=${sbindir}/vgscan
be2d9395 28lvm_lvdisplay=${sbindir}/lvdisplay
edd86b1f 29
630e13ed 30CLVMDOPTS="-T30"
edd86b1f
AK
31
32[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster
630e13ed 33[ -f /etc/sysconfig/$DAEMON ] && . /etc/sysconfig/$DAEMON
edd86b1f 34
d3e282c9
CC
35[ -n "$CLVMD_CLUSTER_IFACE" ] && CLVMDOPTS="$CLVMDOPTS -I $CLVMD_CLUSTER_IFACE"
36
630e13ed
FDN
37# allow up to $CLVMD_STOP_TIMEOUT seconds to clvmd to complete exit operations
38# default to 10 seconds
39
40[ -z $CLMVD_STOP_TIMEOUT ] && CLVMD_STOP_TIMEOUT=10
41
edd86b1f
AK
42LOCK_FILE="/var/lock/subsys/$DAEMON"
43
630e13ed
FDN
44# NOTE: replace this with vgs, once display filter per attr is implemented.
45clustered_vgs() {
46 ${lvm_vgdisplay} 2>/dev/null | \
47 awk 'BEGIN {RS="VG Name"} {if (/Clustered/) print $1;}'
48}
49
be2d9395 50clustered_active_lvs() {
630e13ed 51 for i in $(clustered_vgs); do
be2d9395
MB
52 ${lvm_lvdisplay} $i 2>/dev/null | \
53 awk 'BEGIN {RS="LV Name"} {if (/[^N^O^T] available/) print $1;}'
edd86b1f 54 done
630e13ed 55}
edd86b1f 56
630e13ed
FDN
57rh_status() {
58 status $DAEMON
edd86b1f
AK
59}
60
630e13ed
FDN
61rh_status_q() {
62 rh_status >/dev/null 2>&1
63}
64
65start()
edd86b1f 66{
630e13ed
FDN
67 if ! rh_status_q; then
68 echo -n "Starting $DAEMON: "
2565ffad 69 $DAEMON $CLVMDOPTS || return $?
edd86b1f 70 echo
630e13ed
FDN
71 fi
72
73 # Refresh local cache.
74 #
75 # It's possible that new PVs were added to this, or other VGs
76 # while this node was down. So we run vgscan here to avoid
77 # any potential "Missing UUID" messages with subsequent
78 # LVM commands.
79
80 # The following step would be better and more informative to the user:
81 # 'action "Refreshing VG(s) local cache:" ${lvm_vgscan}'
82 # but it could show warnings such as:
83 # 'clvmd not running on node x-y-z Unable to obtain global lock.'
84 # and the action would be shown as FAILED when in reality it didn't.
85 # Ideally vgscan should have a startup mode that would not print
86 # unnecessary warnings.
87
88 ${lvm_vgscan} > /dev/null 2>&1
89
90 action "Activating VG(s):" ${lvm_vgchange} -ayl $LVM_VGS || return $?
91
92 touch $LOCK_FILE
93
94 return 0
edd86b1f
AK
95}
96
97wait_for_finish()
98{
99 count=0
630e13ed
FDN
100 while [ "$count" -le "$CLVMD_STOP_TIMEOUT" ] && \
101 rh_status_q ]; do
edd86b1f 102 sleep 1
630e13ed 103 count=$((count+1))
edd86b1f 104 done
630e13ed
FDN
105
106 ! rh_status_q
107}
108
109stop()
110{
111 rh_status_q || return 0
112
3ab04a08
FDN
113 [ -z "$LVM_VGS" ] && LVM_VGS="$(clustered_vgs)"
114 if [ -n "$LVM_VGS" ]; then
115 action "Deactivating clustered VG(s):" ${lvm_vgchange} -anl $LVM_VGS || return $?
116 fi
630e13ed
FDN
117
118 action "Signaling $DAEMON to exit" kill -TERM $(pidofproc $DAEMON) || return $?
119
120 # wait half second before we start the waiting loop or we will show
121 # the loop more time than really necessary
122 usleep 500000
123
124 # clvmd could take some time to stop
125 rh_status_q && action "Waiting for $DAEMON to exit:" wait_for_finish
126
127 if rh_status_q; then
128 echo -n "$DAEMON failed to exit"
129 failure
130 echo
edd86b1f
AK
131 return 1
132 else
630e13ed
FDN
133 echo -n "$DAEMON terminated"
134 success
135 echo
edd86b1f 136 fi
edd86b1f 137
630e13ed 138 rm -f $LOCK_FILE
613a355c 139
630e13ed 140 return 0
613a355c
MS
141}
142
630e13ed
FDN
143reload() {
144 rh_status_q || exit 7
145 action "Reloading $DAEMON configuration: " $DAEMON -R || return $?
613a355c
MS
146}
147
630e13ed
FDN
148restart() {
149 # if stop fails, restart will return the error and not attempt
150 # another start. Even if start is protected by rh_status_q,
151 # that would avoid spawning another daemon, it would try to
152 # reactivate the VGs.
c407d2bd
CC
153
154 # Try to get clvmd to restart itself. This will preserve
155 # exclusive LV locks
850fa823 156 action "Restarting $DAEMON: " $DAEMON -S
c407d2bd
CC
157
158 # If that fails then do a normal stop & restart
159 if [ $? != 0 ]; then
160 stop && start
850fa823 161 return $?
c407d2bd
CC
162 else
163 touch $LOCK_FILE
850fa823 164 return 0
c407d2bd 165 fi
630e13ed 166}
edd86b1f 167
2565ffad
FDN
168[ "$EUID" != "0" ] && {
169 echo "clvmd init script can only be executed as root user"
170 exit 4
171}
172
edd86b1f
AK
173# See how we were called.
174case "$1" in
175 start)
176 start
177 rtrn=$?
edd86b1f
AK
178 ;;
179
180 stop)
181 stop
182 rtrn=$?
edd86b1f
AK
183 ;;
184
630e13ed
FDN
185 restart|force-reload)
186 restart
edd86b1f
AK
187 rtrn=$?
188 ;;
189
630e13ed
FDN
190 condrestart|try-restart)
191 rh_status_q || exit 0
192 restart
193 rtrn=$?
194 ;;
195
613a355c 196 reload)
613a355c 197 reload
630e13ed 198 rtrn=$?
613a355c
MS
199 ;;
200
edd86b1f 201 status)
613a355c 202 rh_status
edd86b1f 203 rtrn=$?
630e13ed
FDN
204 if [ $rtrn = 0 ]; then
205 cvgs="$(clustered_vgs)"
be2d9395
MB
206 echo Clustered Volume Groups: ${cvgs:-"(none)"}
207 clvs="$(clustered_active_lvs)"
630e13ed
FDN
208 echo Active clustered Logical Volumes: ${clvs:-"(none)"}
209 fi
edd86b1f
AK
210 ;;
211
212 *)
630e13ed
FDN
213 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
214 rtrn=2
edd86b1f
AK
215 ;;
216esac
217
218exit $rtrn
This page took 0.075015 seconds and 5 git commands to generate.