Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/sh
2
#
3
# iscsid iSCSI daemon
4
#
5
# chkconfig: 345 7 89
6
# description: Starts and stops the iSCSI daemon.
7
#
8
# processname: iscsid
9
# pidfile: /var/run/iscsid.pid
10
# config:  /etc/iscsi/iscsid.conf
11
 
12
### BEGIN INIT INFO
13
# Provides:          iscsid
14
# Default-Start: 3 4 5
15
# Default-Stop: 0 1 2 6
16
# Short-Description: Starts and stops login iSCSI daemon.
17
# Description: iscsid provides the iSCSI session and connection state machine
18
#              for software iscsi/iser (iscsi_tcp/ib_iser) and partialy
19
#              offloaded hardware (bnx2i).
20
### END INIT INFO
21
 
22
# Source function library.
23
. /etc/rc.d/init.d/functions
24
 
25
exec=/sbin/iscsid
26
prog=iscsid
27
config=/etc/iscsi/iscsid.conf
28
lockfile=/var/lock/subsys/$prog
29
iscsi_lockfile=/var/lock/subsys/iscsi
30
 
31
# FIXME this has a false positive for root on nfs
32
root_is_iscsi() {
33
    rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
34
    [[ "$rootopts" =~ "_netdev" ]]
35
}
36
 
37
start_iscsid() {
38
    echo -n $"Starting $prog: "
39
    modprobe -q iscsi_tcp
40
    modprobe -q ib_iser
41
    modprobe -q cxgb3i
42
    modprobe -q cxgb4i
43
    modprobe -q bnx2i
44
    modprobe -q be2iscsi
45
    daemon iscsiuio
46
    daemon $prog
47
    retval=$?
48
    echo
49
    touch $lockfile
50
}
51
 
52
force_start() {
53
    start_iscsid
54
    # a force start could imply the iscsi service is started due to how it
55
    # lazy starts. We need to touch the lock file so it is shutdown later
56
    touch $iscsi_lockfile
57
}
58
 
59
use_discoveryd() {
60
    grep -qrs "discovery.sendtargets.use_discoveryd = Yes" /var/lib/iscsi/send_targets
61
    if [ $? -eq 0 ] ; then
62
 	return 0
63
    fi
64
 
65
    grep -qrs "discovery.isns.use_discoveryd = Yes" /var/lib/iscsi/isns
66
    if [ $? -eq 0 ] ; then
67
 	return 0
68
    fi
69
 
70
    return 1
71
}
72
 
73
start() {
74
    [ -x $exec ] || exit 5
75
    [ -f $config ] || exit 6
76
 
77
    # only start if nodes are setup to startup automatically, root is iscsi,
78
    # or if iscsid is managing the sessions.
79
    grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
80
    if [ $? -eq 0 ] || root_is_iscsi || use_discoveryd ; then
81
        start_iscsid
82
        return $?
83
    fi
84
 
85
    return 0
86
}
87
 
88
stop() {
89
    if use_discoveryd ; then
90
	iscsiadm -k 0 2>/dev/null
91
    fi
92
 
93
    declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|cxgb3i|cxgb4i|be2iscsi") )
94
    if [[ -n "${iparams[*]}" ]]; then
95
        # We have active sessions, so don't stop iscsid!!
96
        echo -n $"Not stopping $prog: iscsi sessions still active"
97
        warning $"Not stopping $prog: iscsi sessions still active"
98
        echo
99
        return 0
100
    fi
101
 
102
    echo -n $"Stopping $prog: "
103
 
104
    iscsiadm -k 0 2>/dev/null
105
    echo
106
 
107
    killproc iscsiuio
108
    rm -f /var/run/iscsiuio.pid
109
 
110
    # only remove the iscsi drivers when offload is used
111
    rmmod bnx2i 2>/dev/null
112
    rmmod cnic 2>/dev/null
113
 
114
    rmmod cxgb3i 2>/dev/null
115
    rmmod cxgb4i 2>/dev/null
116
 
117
    # a bug in kobject netlink code will cause this to oops
118
    # modprobe -r be2iscsi 2>/dev/null
119
 
120
    modprobe -r ib_iser 2>/dev/null
121
    modprobe -r iscsi_tcp 2>/dev/null
122
 
123
    rm -f $lockfile
124
    return 0
125
}
126
 
127
rh_status_q() {
128
    rh_status >/dev/null 2>&1
129
}
130
 
131
restart() {
132
    rh_status_q
133
    use_force_start=$?
134
 
135
    stop
136
    # if iscsid was running then make sure it starts up
137
    if [ "$use_force_start" -eq 0 ] ; then
138
	start_iscsid
139
    else
140
	start
141
    fi
142
}
143
 
144
reload() {
145
    return 3
146
}
147
 
148
force_reload() {
149
    restart
150
}
151
 
152
rh_status() {
153
    status $prog
154
}
155
 
156
case "$1" in
157
    start)
158
        rh_status_q && exit 0
159
        $1
160
        ;;
161
    force-start)
162
        force_start
163
        ;;
164
    stop)
165
        rh_status_q || exit 0
166
        $1
167
        ;;
168
    restart)
169
        $1
170
        ;;
171
    reload)
172
        rh_status_q || exit 7
173
        $1
174
        ;;
175
    force-reload)
176
        force_reload
177
        ;;
178
    status)
179
        rh_status
180
        ;;
181
    condrestart|try-restart)
182
        rh_status_q || exit 0
183
        restart
184
        ;;
185
    *)
186
        echo $"Usage: $0
187
{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
188
        exit 2
189
esac
190
exit $?