I don't if anybody is interested in an initscript to start software raid
services, but I have written one.  I'd be interested in feedback.

the initscript uses raidtab to id the raid devices, it assumes that
fstab has an entry for any devives and if the module for the hostadapter
needs to be loaded, it sould be in modules.conf as raid_hostadapter*.

One thing I know it won't handle is stoping if the mounts are nested
(eg. /dev/md1's mount point is on the filesystem mounted on /dev/md0),
or starting if /dev/md0 is mounted on the /dev/md1 filesystem.

PS. if parts of this look familiar, I started with the alsasound
initscript.

----------------- start --------------------
#!/sbin/runscript
#
# Gentoo users: add this script to 'boot' run level.
# ==================================================
#
# raid                  This shell script takes care of starting and stopping
#                       the raid drive
#
# This script requires /sbin/raidstart and /sbin/raidstop from
# the raidtools package.
#
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA


raidstart=/sbin/raidstart
raidstop=/sbin/raidstop
DEVICES="$(grep "^raiddev" /etc/raidtab | awk '{print $2}')"

load_modules() {

        # List of drivers for each card.
        DRIVERS="$(modprobe -c | egrep
"^[[:space:]]*alias[[:space:]]+raid_hostadapter*"| awk '{print $2}')"

        DRIVERS="${DRIVERS} $(grep raid-level /etc/raidtab|sed
's/.*raid-level[^0-9]*\(.*\)$/raid\1/')"


        for DRIVER in ${DRIVERS}
        do
                if [ ! "${DRIVER}" = off ] &&
                   [ -z `cut -d' ' -f1 /proc/modules | egrep "^${DRIVER}\$"` ] 
&&
                   [ -z `cut -d' ' -f1 /proc/modules | egrep 
"^${DRIVER//-/_}\$"` ];
then
                        ebegin "  Loading module: ${DRIVER}"
                        /sbin/modprobe ${DRIVER}
                        eend $?
                fi
        done

}

mount_devices() {

        for DEVICE in ${DEVICES}
        do
                ebegin "  Mounting ${DEVICE}"
                if $raidstart ${DEVICE}; then
                        mount ${DEVICE}
                fi
                eend $?
        done
}

umount_devices() {

        for DEVICE in ${DEVICES}
        do
                ebegin "  Unmounting ${DEVICE}"
                if umount $DEVICE; then
                        $raidstop ${DEVICE}
                fi
                eend $?
        done
}

start() {

        if [ -f /proc/modules ]; then
                ebegin "Starting Raid services"
                if load_modules; then
                        eend 0
                else
                        eend 1
                        return 1
                fi
        fi

        mount_devices
}

stop() {

        ebegin "Stopping Raid services"
        umount_devices;

        DRIVERS="$(modprobe -c | egrep
"^[[:space:]]*alias[[:space:]]+raid_hostadapter*"| awk '{print $2}')"
        DRIVERS="${DRIVERS} $(lsmod | grep -E "raid" | awk '{print $1}')"

        DRIVERS=$(echo ${DRIVERS})
        ebegin "  Unloading modules ${DRIVERS}"
        modprobe -r ${DRIVERS}

        eend $?
}
-------------------------
-- 
Brian Beattie <[EMAIL PROTECTED]>
#!/sbin/runscript
#
# Gentoo users: add this script to 'boot' run level.
# ==================================================
#
# raid                  This shell script takes care of starting and stopping
#                       the raid drive
#
# This script requires /sbin/raidstart and /sbin/raidstop from
# the raidtools package.
#
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA


raidstart=/sbin/raidstart
raidstop=/sbin/raidstop
DEVICES="$(grep "^raiddev" /etc/raidtab | awk '{print $2}')"

load_modules() {

        # List of drivers for each card.
        DRIVERS="$(modprobe -c | egrep 
"^[[:space:]]*alias[[:space:]]+raid_hostadapter*"| awk '{print $2}')"

        DRIVERS="${DRIVERS} $(grep raid-level /etc/raidtab|sed 
's/.*raid-level[^0-9]*\(.*\)$/raid\1/')"


        for DRIVER in ${DRIVERS}
        do
                if [ ! "${DRIVER}" = off ] &&
                   [ -z `cut -d' ' -f1 /proc/modules | egrep "^${DRIVER}\$"` ] 
&&
                   [ -z `cut -d' ' -f1 /proc/modules | egrep 
"^${DRIVER//-/_}\$"` ]; then
                        ebegin "  Loading module: ${DRIVER}"
                        /sbin/modprobe ${DRIVER}
                        eend $?
                fi
        done

}

mount_devices() {

        for DEVICE in ${DEVICES}
        do
                ebegin "  Mounting ${DEVICE}"
                if $raidstart ${DEVICE}; then
                        mount ${DEVICE}
                fi
                eend $?
        done
}

umount_devices() {

        for DEVICE in ${DEVICES}
        do
                ebegin "  Unmounting ${DEVICE}"
                if umount $DEVICE; then
                        $raidstop ${DEVICE}
                fi
                eend $?
        done
}

start() {

        if [ -f /proc/modules ]; then
                ebegin "Starting Raid services"
                if load_modules; then
                        eend 0
                else
                        eend 1
                        return 1
                fi
        fi

        mount_devices
}

stop() {

        ebegin "Stopping Raid services"
        umount_devices;

        DRIVERS="$(modprobe -c | egrep 
"^[[:space:]]*alias[[:space:]]+raid_hostadapter*"| awk '{print $2}')"
        DRIVERS="${DRIVERS} $(lsmod | grep -E "raid" | awk '{print $1}')"

        DRIVERS=$(echo ${DRIVERS})
        ebegin "  Unloading modules ${DRIVERS}"
        modprobe -r ${DRIVERS}

        eend $?
}

--
[email protected] mailing list

Reply via email to