# description: blockdev
#
# processname: blockdev
-# config:
-# pidfile:
+
+[ -f /etc/sysconfig/blockdev ] || exit 0
+
+blockdevs=$(awk -F= '!/^#/ && !/^$/ {if ($2) print $1}' /etc/sysconfig/blockdev)
+if [ -z "$blockdevs" ]; then
+ case "$1" in
+ start|stop|restart|force-reload)
+ exit 0
+ ;;
+ esac
+fi
# Source function library.
. /etc/rc.d/init.d/functions
-# Source blockdev configureation.
-[ -f /etc/sysconfig/blockdev ] && . /etc/sysconfig/blockdev
+# Source blockdev configuration.
+. /etc/sysconfig/blockdev
start() {
- if [ ! -f /var/lock/subsys/blockdev ]; then
- for drive in $(ls /sys/block 2> /dev/null; ls /dev/mapper 2> /dev/null); do
- if [ -e "/dev/${drive}" ]; then
- eval PARAMS=\$BLOCKDEV_$(echo $drive | tr - _)
- if [ -n "${PARAMS}" ]; then
- show "Setting parameters for block drive %s (%s)" "$drive" "$PARAMS"
- busy
- /sbin/blockdev ${PARAMS} /dev/${drive}
- ok
- fi
- fi
- done
- RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/blockdev
- else
+ if [ -f /var/lock/subsys/blockdev ]; then
msg_already_running blockdev
+ return
fi
+
+ local var realdrive drive PARAMS
+ for var in $blockdevs; do
+ realdrive=
+ drive=${var#BLOCKDEV_}
+ if [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
+ realdrive="/dev/${drive}"
+ elif [ -e "/dev/mapper/${drive}" ]; then
+ realdrive="/dev/mapper/${drive}"
+ elif drive=$(echo $drive | tr _ -) && [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
+ realdrive="/dev/${drive}"
+ elif [ -e "/dev/mapper/${drive}" ]; then
+ realdrive="/dev/mapper/${drive}"
+ fi
+
+ if [ -n "$realdrive" ]; then
+ eval PARAMS=\$$var
+ if [ -n "${PARAMS}" ]; then
+ show "Setting parameters for block drive %s (%s)" "$drive" "$PARAMS"
+ busy
+ /sbin/blockdev ${PARAMS} $realdrive
+ ok
+ fi
+ fi
+ done
+ # TODO: retval not really handled here
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/blockdev
}
stop() {
# Stop daemons.
if [ ! -f /var/lock/subsys/blockdev ]; then
msg_not_running blockdev
+ return
fi
rm -f /var/lock/subsys/blockdev
}
+status() {
+ if [ -z "$blockdevs" ]; then
+ echo "no devices configured for blockdev"
+ RETVAL=1
+ return
+ fi
+
+ echo "blockdev configured for:"
+ local var drive realdrive PARAMS
+ for var in $blockdevs; do
+ drive=${var#BLOCKDEV_}
+ echo -n "- $drive: "
+
+ realdrive=
+ if [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
+ realdrive="/dev/${drive}"
+ elif [ -e "/dev/mapper/${drive}" ]; then
+ realdrive="/dev/mapper/${drive}"
+ elif drive=$(echo $drive | tr _ -) && [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
+ realdrive="/dev/${drive}"
+ elif [ -e "/dev/mapper/${drive}" ]; then
+ realdrive="/dev/mapper/${drive}"
+ fi
+
+ eval PARAMS=\$$var
+ if [ -n "$realdrive" ]; then
+ echo "${PARAMS}; device=$realdrive"
+ else
+ echo "${PARAMS}; device not present"
+ fi
+ done
+}
+
RETVAL=0
# See how we were called.
case "$1" in
start
;;
status)
- status blockdev
- exit $?
+ status
;;
*)
msg_usage "$0 {start|stop|restart|force-reload|status}"