blob: 9024151731c3358d9784dd406f45b53ac4d2b9d0 (
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
#!/bin/sh -eu
#
# Start all arrays specified in the configuration file.
#
# Copyright © 2001-2005 Mario Jou/3en <joussen@debian.org>
# Copyright © 2005-2006 Martin F. Krafft <madduck@debian.org>
# Distributable under the terms of the GNU GPL version 2.
#
# $Id$
#
MDADM=/sbin/mdadm
CONFIG=/etc/mdadm/mdadm.conf
ALTCONFIG=/etc/mdadm.conf
DEBIANCONFIG=/etc/default/mdadm
test -x $MDADM || exit 0
AUTOSTART=true
test -f $DEBIANCONFIG && . $DEBIANCONFIG
. /lib/lsb/init-functions
short_dev()
{
local dev=${1##*/}
case "$dev" in
md*|md_*|mdp*|mdp_*) echo "$dev";;
*) echo "md${dev}";;
esac
}
log()
{
case "$1" in
[[:digit:]]*) success=$1; shift;;
*) :;;
esac
log_action_begin_msg "$1"; shift
log_action_end_msg ${success:-0} "$*"
}
log_dev()
{
success=${1:-}; shift
dev=${1:-}; shift
log $success "${PREFIX:-} $(short_dev ${dev:-})" "$*"
}
log_notice()
{
log 0 "${PREFIX:-}s" "$*"
}
log_problem()
{
log 1 "${PREFIX:-}s" "$*"
}
is_true()
{
case "${1:-}" in
[Yy]es|[Yy]|1|[Tt]rue|[Tt]) return 0;;
*) return 1;
esac
}
case "${1:-}" in
start)
PREFIX="Assembling RAID array"
if is_true $AUTOSTART; then
if [ ! -f /proc/mdstat ] && [ -x "$(command -v modprobe)" ] ; then
modprobe -kq md 2>/dev/null || :
fi
if [ ! -f /proc/mdstat ]; then
log_problem "failed to load RAID subsystem"
exit 0
fi
if [ -f $CONFIG ] || [ -f $ALTCONFIG ]; then
# handle devfs-style names and version-1 devices
mkdir --parent /dev/md
# ugly hack because shell sucks
IFSOLD=${IFS:-}
IFS='
'
for line in $($MDADM --assemble --scan --auto=yes 2>&1); do
IFS=$IFSOLD
set -- $line
shift
case "$@" in
'No arrays found in config file')
# no point in carrying on.
shift
log_problem "no $*"
exit 0
;;
'Unknown keyword'*)
# warn only
if [ -x $(command -v logger >/dev/null) ]; then
logger -t mdadm -p syslog.warning -- "$*"
elif [ -w /dev/console ]; then
echo "mdadm: $*" > /dev/console
else
echo "mdadm: $*" >&2
fi
;;
*' is already active.')
log_dev 0 $1 "already running"
;;
*'has been started with '[[:digit:]]*' drives.')
log_dev 0 $1 "started [$6/$6]"
;;
*'has been started with '[[:digit:]]*' drives (out of '[[:digit:]]*').')
log_dev 0 $1 "degraded [$6/${10%).}]"
;;
*'assembled from '[[:digit:]]*' drive's#' - not enough to start the array.')
log_dev 1 $1 "not enough devices"
;;
'no devices found for '*)
log_dev 1 $5 "no devices found"
;;
'failed to RUN_ARRAY '*': Input/output error')
log_dev 1 ${4%:} "RUN_ARRAY input/output error"
;;
*) :;;
esac
done || exit $?
else
log_problem "no $CONFIG file"
fi
else
log_notice "disabled in $DEBIANCONFIG"
fi
;;
stop)
PREFIX="Stopping RAID array"
if is_true $AUTOSTART; then
if [ ! -f /proc/mdstat ]; then
log_problem "no RAID subsystem loaded"
exit 0
fi
# ugly hack because shell sucks
IFSOLD=${IFS:-}
IFS='
'
set +e
for line in $($MDADM --stop --scan 2>&1); do
set -e
IFS=$IFSOLD
set -- $line
shift
case "$@" in
'Unknown keyword'*)
# warn only
if [ -x $(command -v logger >/dev/null) ]; then
logger -t mdadm -p syslog.warning -- "$*"
elif [ -w /dev/console ]; then
echo "mdadm: $*" > /dev/console
else
echo "mdadm: $*" >&2
fi
;;
'stopped '*)
log_dev 0 $2 stopped
;;
'fail to stop array '*': Device or resource busy')
log_dev 1 ${5%:} busy
;;
*) :;;
esac
done || exit $?
else
log_notice "disabled in $DEBIANCONFIG"
fi
;;
restart)
${0:-} stop
${0:-} start
;;
reload|force-reload)
PREFIX="Reloading RAID array"
log_notice "never anything to do"
;;
*)
echo "Usage: ${0:-} {start|stop|restart}" >&2
exit 1;;
esac
exit 0
|