File: raid2

package info (click to toggle)
raidtools2 0.90.20010914-15
  • links: PTS
  • area: main
  • in suites: woody
  • size: 692 kB
  • ctags: 467
  • sloc: ansic: 2,861; sh: 187; makefile: 144
file content (134 lines) | stat: -rw-r--r-- 2,555 bytes parent folder | download
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
#!/bin/sh
#
# Startup RAID-arrays that aren't already running, or stop
# all active arrays mentioned in raidtab.
#
# Written by Rainer Weikusat <weikusat@students.uni-mainz.de>
# Some modifications by Pekka Aleksi Knuutila <pa@debian.org>

#*  parameters
#
PATH=/sbin:/bin

RAIDSTART=/sbin/raidstart
RAIDSTOP=/sbin/raidstop
RAID0RUN=/sbin/raid0run
CONFIG=/etc/raidtab

#*  functions
#
list_devices()
{
    sed 's/#.*$//' $CONFIG | grep raiddev | while read REPLY;
    do
        set -- $REPLY
        echo $2
    done
}

is_active()
{
    # remove the leading /dev/, and possibly / from the middle
    NAME=$(echo $1 | sed -e 's/^\/dev\/\(md\)\/*\(.*\)$/\1\2/')
    
    grep -q "^$NAME : active" /proc/mdstat
}

read_param()			# $1: raiddev $2: param-name
{
    DEV="$1"
    PARAM="$2"
    
    sed 's/#.*$//' $CONFIG | while read REPLY;
    do
    set -- $REPLY
	
    if [ "$1" = raiddev -a "$2" = $DEV ];
    then
        while read REPLY;
        do
            set -- $REPLY
            
            if [ "$1" = raiddev ];
            then
                break
            fi
            
            if [ "$1" = $PARAM ];
            then
                echo $2
            fi
        done
        return
    fi
    done
}

start_device()
{
    DEV="$1"
    
    if [ "$(read_param $DEV persistent-superblock)" != 0 ];
    then
        $RAIDSTART --configfile $CONFIG $DEV && echo -n "$DEV "
    else
        case "$(read_param $DEV raid-level)" in
            0|linear)
            $RAID0RUN --configfile $CONFIG $DEV && echo -n "$DEV "
            ;;
	    
            *)
            echo "Cannot auto-start old-style $DEV. See mkraid(8), -o" >&2
            ;;
        esac

    fi
}

#*  main code
#
if [ ! -f /proc/mdstat -a -x /sbin/modprobe ]; then
    modprobe -k md > /dev/null 2>&1  
fi
if [ ! -f /proc/mdstat ]; then
    echo 'raidtools2 init script failed; RAID drivers not available.' >&2 
	exit 1
fi

test -f $CONFIG || exit 0

case "$1" in
    start)
    test -x $RAIDSTART && test -x $RAID0RUN || exit 0

    echo -n 'Starting RAID devices: '

    list_devices | while read REPLY;
    do
        is_active $REPLY && continue
        start_device $REPLY
    done

    echo done.
    ;;

    stop)
    test -x $RAIDSTOP || exit 0

    echo -n 'Stopping RAID devices: '

    list_devices | while read REPLY;
    do
        is_active $REPLY || continue
        $RAIDSTOP --configfile $CONFIG $REPLY && echo -n "$REPLY "
    done

    echo done.
    ;;

    restart|reload|force-reload)
    $0 stop
    sleep 2
    $0 start
    ;;
esac