forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-02-17 557c24d082b6ecb9bfe5407b77ae43fa7650a5dc
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
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
#
# multipathd    Starts the multipath daemon
#
# chkconfig: - 06 87
# description: Manages device-mapper multipath devices
 
### BEGIN INIT INFO
# Provides: multipathd
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Control multipathd
# Description: This service monitors and manages
#              device-mapper multipath devices
### END INIT INFO
 
DAEMON=/sbin/multipathd
prog=`basename $DAEMON`
initdir=/etc/init.d
lockdir=/var/lock/subsys
sysconfig=/etc/sysconfig
syspath=/sys/block
 
RETVAL=0
 
teardown_slaves()
{
pushd $1 > /dev/null
if [ -d "slaves" ]; then
for slave in slaves/*;
do
   if [ "$slave" = "slaves/*" ]; then
       read dev <  $1/dev
       tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
       if ! [ -z $tablename ]; then
           echo "Root is on a multipathed device, multipathd can not be stopped"
           exit 1
       fi
   else
       local_slave=`readlink -f $slave`;
       teardown_slaves $local_slave;
   fi
   done
 
else
       read dev <  $1/dev
       tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
       if ! [ -z $tablename ]; then
           echo "Root is on a multipathed device, multipathd can not be stopped"
           exit 1
       fi
fi
popd > /dev/null
}
 
#
# See how we were called.
#
 
start() {
   test -x $DAEMON || exit 5
   echo -n $"Starting $prog daemon: "
   start-stop-daemon --start --quiet --exec $DAEMON
   RETVAL=$?
   [ $RETVAL -eq 0 ] && touch $lockdir/$prog
   echo
}
 
force_stop() {
   echo -n $"Stopping $prog daemon: "
   killall $DAEMON
   RETVAL=$?
   [ $RETVAL -eq 0 ] && rm -f $lockdir/$prog
   echo
}
 
stop() {
        root_dev=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/mtab)
   dm_num=`dmsetup info -c --noheadings -o minor $root_dev 2> /dev/null`
   if [ $? -eq 0 ]; then
       root_dm_device="dm-$dm_num"
       [ -d $syspath/$root_dm_device ] && teardown_slaves $syspath/$root_dm_device
   fi
 
   force_stop
}
 
restart() {
   stop
   start
}
 
force_restart() {
   force_stop
   start
}
 
reload() {
   echo -n "Reloading $prog: "
   trap "" SIGHUP
   killall $DAEMON -s SIGHUP -v
   RETVAL=$?
   echo
}    
 
case "$1" in
start)
   start
   ;;
stop)
   stop
   ;;
force-stop)
   force_stop
   ;;
force-reload|reload)
   reload
   ;;
restart)
   restart
   ;;
force-restart)
   force_restart
   ;;
condrestart|try-restart)
   if [ -f $lockdir/$prog ]; then
       restart
   fi
   ;;
status)
    if pidof -o %PPID $DAEMON > /dev/null; then
        echo "Running"
        RETVAL=0
    else
        echo "Not running"
        RETVAL=1
    fi
   ;;
*)
   echo $"Usage: $0 {start|stop|force-stop|status|restart|force-restart|condrestart|reload}"
   RETVAL=2
esac
 
exit $RETVAL