]> git.pld-linux.org Git - packages/util-linux.git/blame - util-linux-blockdev.init
- copied from util-linux-ng
[packages/util-linux.git] / util-linux-blockdev.init
CommitLineData
f212f39a 1#!/bin/sh
2#
3# blockdev This shell script takes care of starting and stopping blockdev.
4#
5# chkconfig: 2345 01 99
6# description: blockdev
7#
8# processname: blockdev
9# config:
10# pidfile:
11
12[ -f /etc/sysconfig/blockdev ] || exit 0
13
14blockdevs=$(awk -F= '!/^#/ && !/^$/ {if ($2) print $1}' /etc/sysconfig/blockdev)
15if [ -z "$blockdevs" ]; then
16 case "$1" in
17 start|stop|restart|force-reload)
18 exit 0
19 ;;
20 esac
21fi
22
23# Source function library.
24. /etc/rc.d/init.d/functions
25
26# Source blockdev configuration.
27. /etc/sysconfig/blockdev
28
29start() {
30 if [ ! -f /var/lock/subsys/blockdev ]; then
31 for var in $blockdevs; do
32 realdrive=
33 drive=${var#BLOCKDEV_}
34 if [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
35 realdrive="/dev/${drive}"
36 elif [ -e "/dev/mapper/${drive}" ]; then
37 realdrive="/dev/mapper/${drive}"
38 elif drive=$(echo $drive | tr _ -) && [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
39 realdrive="/dev/${drive}"
40 elif [ -e "/dev/mapper/${drive}" ]; then
41 realdrive="/dev/mapper/${drive}"
42 fi
43
44 if [ -n "$realdrive" ]; then
45 eval PARAMS=\$$var
46 if [ -n "${PARAMS}" ]; then
47 show "Setting parameters for block drive %s (%s)" "$drive" "$PARAMS"
48 busy
49 /sbin/blockdev ${PARAMS} $realdrive
50 ok
51 fi
52 fi
53 done
54 RETVAL=$?
55 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/blockdev
56 else
57 msg_already_running blockdev
58 fi
59}
60
61stop() {
62 # Stop daemons.
63 if [ ! -f /var/lock/subsys/blockdev ]; then
64 msg_not_running blockdev
65 fi
66 rm -f /var/lock/subsys/blockdev
67}
68
69RETVAL=0
70# See how we were called.
71case "$1" in
72 start)
73 start
74 ;;
75 stop)
76 stop
77 ;;
78 restart|force-reload)
79 stop
80 start
81 ;;
82 status)
83 if [ "$blockdevs" ]; then
84 echo "blockdev configured for:"
85 for var in $blockdevs; do
86 drive=${var#BLOCKDEV_}
87 echo -n "- $drive: "
88
89 realdrive=
90 if [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
91 realdrive="/dev/${drive}"
92 elif [ -e "/dev/mapper/${drive}" ]; then
93 realdrive="/dev/mapper/${drive}"
94 elif drive=$(echo $drive | tr _ -) && [ -d "/sys/block/${drive}" -a -e "/dev/${drive}" ]; then
95 realdrive="/dev/${drive}"
96 elif [ -e "/dev/mapper/${drive}" ]; then
97 realdrive="/dev/mapper/${drive}"
98 fi
99
100 eval PARAMS=\$$var
101 if [ -n "$realdrive" ]; then
102 echo "${PARAMS}; device=$realdrive"
103 else
104 echo "${PARAMS}; device not present"
105 fi
106
107 done
108 else
109 echo "no devices configured for blockdev"
110 fi
111 ;;
112 *)
113 msg_usage "$0 {start|stop|restart|force-reload|status}"
114 exit 3
115esac
116
117exit $RETVAL
This page took 0.042664 seconds and 4 git commands to generate.