iscsi-initiator-utils/iscsid.init

191 lines
3.9 KiB
Plaintext
Raw Normal View History

2007-03-20 19:39:20 +00:00
#!/bin/sh
#
# iscsid iSCSI daemon
#
2007-03-20 19:39:20 +00:00
# chkconfig: 345 7 89
# description: Starts and stops the iSCSI daemon.
#
# processname: iscsid
# pidfile: /var/run/iscsid.pid
# config: /etc/iscsi/iscsid.conf
### BEGIN INIT INFO
# Provides: iscsid
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Starts and stops login iSCSI daemon.
# Description: iscsid provides the iSCSI session and connection state machine
# for software iscsi/iser (iscsi_tcp/ib_iser) and partialy
# offloaded hardware (bnx2i).
### END INIT INFO
2007-03-20 19:39:20 +00:00
# Source function library.
. /etc/rc.d/init.d/functions
exec=/sbin/iscsid
prog=iscsid
config=/etc/iscsi/iscsid.conf
lockfile=/var/lock/subsys/$prog
iscsi_lockfile=/var/lock/subsys/iscsi
# FIXME this has a false positive for root on nfs
root_is_iscsi() {
rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
[[ "$rootopts" =~ "_netdev" ]]
}
2011-02-20 04:24:00 +00:00
start_iscsid() {
echo -n $"Starting $prog: "
modprobe -q iscsi_tcp
modprobe -q ib_iser
2010-01-15 11:53:18 +00:00
modprobe -q cxgb3i
modprobe -q cxgb4i
2010-01-15 11:53:18 +00:00
modprobe -q bnx2i
2010-01-25 19:17:05 +00:00
modprobe -q be2iscsi
2010-01-15 11:53:18 +00:00
daemon brcm_iscsiuio
daemon $prog
retval=$?
echo
touch $lockfile
2011-02-20 04:24:00 +00:00
}
force_start() {
start_iscsid
# a force start could imply the iscsi service is started due to how it
# lazy starts. We need to touch the lock file so it is shutdown later
touch $iscsi_lockfile
}
2010-05-19 10:38:36 +00:00
use_discoveryd() {
2010-07-11 09:27:41 +00:00
grep -qrs "discovery.sendtargets.use_discoveryd = Yes" /var/lib/iscsi/send_targets
if [ $? -eq 0 ] ; then
return 0
2010-05-19 10:38:36 +00:00
fi
2010-07-11 09:27:41 +00:00
grep -qrs "discovery.isns.use_discoveryd = Yes" /var/lib/iscsi/isns
if [ $? -eq 0 ] ; then
return 0
fi
return 1
2010-05-19 10:38:36 +00:00
}
start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
2010-05-19 10:38:36 +00:00
# only start if nodes are setup to startup automatically, root is iscsi,
# or if iscsid is managing the sessions.
grep -qrs "node.startup = automatic" /var/lib/iscsi/nodes
2010-05-19 10:38:36 +00:00
if [ $? -eq 0 ] || root_is_iscsi || use_discoveryd ; then
2011-02-20 04:24:00 +00:00
start_iscsid
return $?
fi
return 0
2007-03-20 19:39:20 +00:00
}
stop() {
2010-05-19 10:38:36 +00:00
if use_discoveryd ; then
iscsiadm -k 0 2>/dev/null
fi
declare -a iparams=( $(iscsiadm -m session 2>/dev/null | egrep "tcp|iser|bnx2i|cxgb3i|cxgb4i|be2iscsi") )
if [[ -n "${iparams[*]}" ]]; then
# We have active sessions, so don't stop iscsid!!
echo -n $"Not stopping $prog: iscsi sessions still active"
warning $"Not stopping $prog: iscsi sessions still active"
echo
return 0
fi
echo -n $"Stopping $prog: "
2010-01-25 19:17:05 +00:00
2010-05-19 10:38:36 +00:00
iscsiadm -k 0 2>/dev/null
echo
2010-01-25 19:17:05 +00:00
killproc brcm_iscsiuio
rm -f /var/run/brcm_iscsiuio.pid
# only remove the iscsi drivers when offload is used
rmmod bnx2i 2>/dev/null
rmmod cnic 2>/dev/null
rmmod cxgb3i 2>/dev/null
rmmod cxgb4i 2>/dev/null
2010-01-25 19:17:05 +00:00
# a bug in kobject netlink code will cause this to oops
# modprobe -r be2iscsi 2>/dev/null
2010-01-25 19:17:05 +00:00
modprobe -r ib_iser 2>/dev/null
modprobe -r iscsi_tcp 2>/dev/null
2010-05-19 10:38:36 +00:00
rm -f $lockfile
return 0
}
rh_status_q() {
rh_status >/dev/null 2>&1
2007-03-20 19:39:20 +00:00
}
restart() {
2010-05-19 10:38:36 +00:00
rh_status_q
use_force_start=$?
stop
2010-05-19 10:38:36 +00:00
# if iscsid was running then make sure it starts up
if [ "$use_force_start" -eq 0 ] ; then
2011-02-20 04:24:00 +00:00
start_iscsid
2010-05-19 10:38:36 +00:00
else
start
fi
2007-03-20 19:39:20 +00:00
}
reload() {
return 3
}
force_reload() {
restart
}
rh_status() {
status $prog
}
2007-03-20 19:39:20 +00:00
case "$1" in
start)
rh_status_q && exit 0
$1
;;
force-start)
force_start
;;
stop)
rh_status_q || exit 0
$1
;;
restart)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0
{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
2007-03-20 19:39:20 +00:00
esac
exit $?