blob: e04424fcd7816001d8ff15f16304077776865a42 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/bin/bash
### BEGIN INIT INFO
# Provides: rbdmap
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ceph RBD Mapping
# Description: Ceph RBD Mapping
### END INIT INFO
DESC="RBD Mapping"
RBDMAPFILE="/etc/ceph/rbdmap"
. /lib/lsb/init-functions
do_map() {
if [ ! -f "$RBDMAPFILE" ]; then
log_warning_msg "$DESC : No $RBDMAPFILE found."
exit 0
fi
log_daemon_msg "Starting $DESC"
# Read /etc/rbdtab to create non-existant mapping
newrbd=
RET=0
while read DEV PARAMS; do
case "$DEV" in
""|\#*)
continue
;;
*/*)
;;
*)
DEV=rbd/$DEV
;;
esac
OIFS=$IFS
IFS=','
for PARAM in ${PARAMS[@]}; do
CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"
done
IFS=$OIFS
if [ ! -b /dev/rbd/$DEV ]; then
log_progress_msg $DEV
rbd map $DEV $CMDPARAMS
[ $? -ne "0" ] && RET=1
newrbd="yes"
fi
done < $RBDMAPFILE
log_end_msg $RET
# Mount new rbd
if [ "$newrbd" ]; then
log_action_begin_msg "Mounting all filesystems"
mount -a
log_action_end_msg $?
fi
}
do_unmap() {
log_daemon_msg "Stopping $DESC"
RET=0
# Recursive umount that depends /dev/rbd*
MNTDEP=$(findmnt --mtab | awk '$2 ~ /^\/dev\/rbd[0-9]*$/ {print $1}' | sort -r)
for MNT in $MNTDEP; do
umount $MNT
done
# Unmap all rbd device
if ls /dev/rbd[0-9]* >/dev/null 2>&1; then
for DEV in /dev/rbd[0-9]*; do
log_progress_msg $DEV
rbd unmap $DEV
[ $? -ne "0" ] && RET=1
done
fi
log_end_msg $RET
}
case "$1" in
start)
do_map
;;
stop)
do_unmap
;;
reload)
do_map
;;
status)
rbd showmapped
;;
*)
log_success_msg "Usage: rbdmap {start|stop|reload|status}"
exit 1
;;
esac
exit 0
|