2011-01-07 19:52:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
. /etc/rc.conf
|
|
|
|
. /etc/rc.d/functions
|
|
|
|
|
|
|
|
# general config
|
|
|
|
[ -f /etc/conf.d/open-iscsi ] && . /etc/conf.d/open-iscsi
|
|
|
|
|
|
|
|
# Set defaults if settings are missing
|
|
|
|
[ -z "${ISCSID_ARGS}" ] && ISCSID_ARGS=""
|
|
|
|
[ -z "$SEC_BEFORE_MOUNT" ] && SEC_BEFORE_MOUNT=2
|
|
|
|
[ -z "$ISCSIADM_EXTRAARGS" ] && ISCSIADM_EXTRAARGS=""
|
|
|
|
DAEMON_NAME="open-iscsi"
|
2012-05-30 20:52:47 +00:00
|
|
|
ISCSIADM=/sbin/iscsiadm
|
|
|
|
PIDFILE=/var/run/iscsid.pid
|
2011-01-07 19:52:36 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
modprobe -q iscsi_tcp &>/dev/null
|
|
|
|
modprobe -q ib_iser &>/dev/null
|
2012-05-30 20:52:47 +00:00
|
|
|
|
2011-01-07 19:52:36 +00:00
|
|
|
stat_busy "Starting Open-iSCSI daemon"
|
|
|
|
/sbin/iscsid ${ISCSID_ARGS}
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
stat_fail
|
|
|
|
exit 2
|
|
|
|
else
|
|
|
|
add_daemon $DAEMON_NAME
|
|
|
|
stat_done
|
|
|
|
fi
|
|
|
|
|
2012-05-30 20:52:47 +00:00
|
|
|
if [ -n "$SERVER" ]; then
|
|
|
|
stat_busy "Discovering targets"
|
|
|
|
$ISCSIADM -m discovery -t sendtargets -p $SERVER $ISCSIADM_EXTRAARGS > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
stat_fail
|
|
|
|
exit 3
|
|
|
|
else
|
|
|
|
stat_done
|
|
|
|
fi
|
2011-01-07 19:52:36 +00:00
|
|
|
|
2012-05-30 20:52:47 +00:00
|
|
|
stat_busy "Login to all portals"
|
|
|
|
$ISCSIADM -m node -L all > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
stat_fail
|
|
|
|
exit 4
|
|
|
|
else
|
|
|
|
stat_done
|
|
|
|
fi
|
2011-01-07 19:52:36 +00:00
|
|
|
|
2012-05-30 20:52:47 +00:00
|
|
|
if [[ "$MOUNT" != "" ]]; then
|
|
|
|
# wait n seconds to settle
|
|
|
|
sleep $SEC_BEFORE_MOUNT
|
|
|
|
status "Mounting devices"
|
|
|
|
for MTPT in ${MOUNT[@]}; do
|
|
|
|
stat_busy "mounting $MTPT"
|
|
|
|
mount $MTPT
|
|
|
|
sleep 1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
stat_done
|
|
|
|
else
|
|
|
|
stat_fail
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
status "No devices to mount defined"
|
|
|
|
fi
|
2011-01-07 19:52:36 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
if [[ "$MOUNT" != "" ]]; then
|
|
|
|
status "Unmounting devices"
|
|
|
|
# unmounting in reverse order
|
|
|
|
LEN=${#MOUNT[@]}
|
|
|
|
while [ $LEN -ne 0 ]; do
|
|
|
|
let LEN=$LEN-1;
|
|
|
|
UMOUNT="$UMOUNT ${MOUNT[$LEN]}";
|
|
|
|
done
|
|
|
|
for MTPT in $UMOUNT; do
|
2012-05-30 20:52:47 +00:00
|
|
|
MOUNTED=$(mount|grep -c `/usr/bin/readlink -mns $MTPT`)
|
2011-01-07 19:52:36 +00:00
|
|
|
if [ $MOUNTED -ne 0 ]; then
|
|
|
|
stat_busy "unmounting $MTPT"
|
|
|
|
umount $MTPT
|
|
|
|
sleep 1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
stat_done
|
|
|
|
else
|
|
|
|
stat_fail
|
|
|
|
exit 5
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
status "$MTPT not mounted"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
sleep 2
|
|
|
|
else
|
|
|
|
status "No devices to unmount defined"
|
|
|
|
fi
|
|
|
|
|
2012-05-30 20:52:47 +00:00
|
|
|
$ISCSIADM -m session $> /dev/null
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
stat_busy "Logout to all portals"
|
|
|
|
$ISCSIADM -m node -U all > /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
stat_fail
|
|
|
|
exit 6
|
|
|
|
else
|
|
|
|
stat_done
|
|
|
|
fi
|
2011-01-07 19:52:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
stat_busy "Stopping Open-iSCSI daemon"
|
2012-05-30 20:52:47 +00:00
|
|
|
[ -f $PIDFILE ] && kill -9 `cat $PIDFILE` &> /dev/null
|
2011-01-07 19:52:36 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
stat_fail
|
|
|
|
else
|
2012-05-30 20:52:47 +00:00
|
|
|
rm -f $PIDFILE
|
2011-01-07 19:52:36 +00:00
|
|
|
killall iscsid > /dev/null
|
|
|
|
rm_daemon $DAEMON_NAME
|
|
|
|
stat_done
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status "Open-iSCSI status"
|
|
|
|
ck_daemon $DAEMON_NAME
|
|
|
|
status "Available portals on node"
|
|
|
|
echo
|
|
|
|
echo -ne " "
|
|
|
|
/sbin/iscsiadm -m node
|
|
|
|
echo
|
|
|
|
status "Connected portals for this session"
|
|
|
|
echo
|
|
|
|
echo -ne " "
|
|
|
|
/sbin/iscsiadm -m session
|
|
|
|
echo
|
|
|
|
;;
|
|
|
|
statusv)
|
|
|
|
status "Open-iSCSI status"
|
|
|
|
ck_daemon $DAEMON_NAME
|
|
|
|
status "Detailed session info"
|
|
|
|
echo
|
2012-05-30 20:52:47 +00:00
|
|
|
$ISCSIADM -m session -P 2
|
2011-01-07 19:52:36 +00:00
|
|
|
echo
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
$0 stop
|
|
|
|
sleep 2
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "usage: $0 {start|stop|status|statusv|restart}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
exit 0
|