~ubuntu-branches/ubuntu/intrepid/multipath-tools/intrepid-proposed

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
#!/bin/sh

device="$1"

# checking proper invocation and if we have the tools to work.
# sfdisk is part of util-linux (Essential: yes)
if [ -z "$device" ] || ! which sg_start > /dev/null; then
	exit 0
fi

# wait maximum 1 minute for a device to appear in /dev
slumber=600
while [ ${slumber} -gt 0 -a ! -b /dev/$device ]; do
	sleep 0.1
	slumber=$(( ${slumber} - 1 ))
done

# if the device finally exists start it.
if [ -b /dev/$device ]; then
	if ! sg_turs /dev/$device > /dev/null 2>&1; then
		# start the device and wait for it
		sg_start --imm=0 --start /dev/$device
		sleep 2
	fi
	# rescan the device
	echo 1 > /sys/block/$device/device/rescan
	# rescan partition table
	if which sfdisk > /dev/null; then
		sfdisk -R /dev/$device
	fi
	# this is harsh but multipathd needs a hard restart
	kill -9 $(pidof /sbin/multipathd) || true
	multipath -v 0 /dev/$device
	invoke-rc.d multipath-tools start > /dev/null 2>&1 || true
fi

exit 0