2007-05-02 11:19:43 +02:00
|
|
|
#!/sbin/runscript
|
|
|
|
# Copyright 1999-2005 Gentoo Technologies, Inc.
|
|
|
|
# Distributed under the terms of the GNU General Public License, v2 or later
|
|
|
|
# $Header: /var/cvsroot/gentoo-x86/sys-block/open-iscsi/files/iscsid-init.d,v 1.4 2006/03/07 08:26:46 robbat2 Exp $
|
|
|
|
|
|
|
|
PID_FILE=/var/run/iscsid.pid
|
|
|
|
CONFIG_FILE=/etc/iscsi/iscsid.conf
|
|
|
|
DUMP_DIR=/etc/iscsi
|
|
|
|
DUMP_NODE="${DUMP_DIR}/node.dump"
|
|
|
|
DUMP_DISCOVERY="${DUMP_DIR}/discovery.dump"
|
|
|
|
INITIATORNAME=/etc/iscsi/initiatorname.iscsi
|
|
|
|
DAEMON=/usr/sbin/iscsid
|
|
|
|
ADM=/usr/sbin/iscsiadm
|
|
|
|
NAME="iSCSI initiator service"
|
|
|
|
UDEVINFO=/usr/bin/udevinfo
|
|
|
|
|
|
|
|
depend() {
|
|
|
|
after modules
|
|
|
|
use net
|
|
|
|
}
|
|
|
|
|
|
|
|
checkconfig() {
|
|
|
|
if [ ! -f $CONFIG_FILE ]; then
|
|
|
|
eerror "Config file $CONFIG_FILE does not exist!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ ! -f $INITIATORNAME -o -z "$(egrep '^InitiatorName=' "${INITIATORNAME}")" ]; then
|
|
|
|
eerror "$INITIATORNAME should contain a string with your initiatior name, eg:"
|
|
|
|
eerror "InitiatorName=iqn.2005-09.tld.domainname.hostname:initiator-name"
|
|
|
|
eerror "Initiator name file does not exist!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
do_modules() {
|
|
|
|
msg="$1"
|
|
|
|
shift
|
|
|
|
modules="$1"
|
|
|
|
shift
|
|
|
|
opts="$@"
|
|
|
|
for m in ${modules}; do
|
|
|
|
ebegin "${msg} - ${m}"
|
|
|
|
modprobe ${opts} $m
|
|
|
|
ret=$?
|
|
|
|
eend $ret
|
|
|
|
[ $ret -ne 0 ] && return $ret
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
checkconfig || return 1
|
2007-05-02 13:09:44 +02:00
|
|
|
if [ -n "${LOAD_MODULES}" ] ; then
|
|
|
|
do_modules 'Loading iSCSI modules' "${LOAD_MODULES}"
|
|
|
|
fi
|
2007-05-02 11:19:43 +02:00
|
|
|
ret=$?
|
|
|
|
[ $ret -ne 0 ] && return 1
|
|
|
|
ebegin "Starting ${NAME}"
|
|
|
|
start-stop-daemon --start --exec $DAEMON --quiet -- -i $INITIATORNAME
|
|
|
|
ret=$?
|
|
|
|
eend $ret
|
|
|
|
|
|
|
|
ebegin "Logging in to all automatic nodes"
|
|
|
|
${ADM} -m node -L automatic
|
|
|
|
ret=$?
|
|
|
|
eend $ret
|
|
|
|
|
|
|
|
sleep 5
|
|
|
|
|
|
|
|
ebegin "Mounting all disks with entries in /etc/fstab"
|
|
|
|
PARTITIONS=""
|
2007-05-02 13:31:32 +02:00
|
|
|
ISCSI_SESSION="`iscsiadm -m session -i 2>/dev/null | grep '^Attached scsi disk '`"
|
|
|
|
if [ "x${?}" == "x0" ] ; then
|
|
|
|
DISKS="`echo ${ISCSI_SESSION} | awk '{ print $4; }'`"
|
2007-05-02 11:19:43 +02:00
|
|
|
|
2007-05-02 13:31:32 +02:00
|
|
|
for DISK in "${DISKS}" ; do
|
|
|
|
PARTITIONS="`find /dev -name \"${DISK}[0-9]*\" | grep -v '\.udev/'` ${PARTITIONS}"
|
|
|
|
done
|
2007-05-02 11:19:43 +02:00
|
|
|
|
2007-05-02 13:31:32 +02:00
|
|
|
for PARTITION in "${PARTITIONS}" ; do
|
|
|
|
PART_LABEL="`${UDEVINFO} -q env -n ${PARTITION} | grep '^ID_FS_LABEL=' | awk -F '=' '{ print $2; }'`"
|
|
|
|
IN_FSTAB="`grep ${PART_LABEL} /etc/fstab`"
|
2007-05-02 11:19:43 +02:00
|
|
|
|
2007-05-02 13:31:32 +02:00
|
|
|
if [ "x${IN_FSTAB}" != "x" ] ; then
|
|
|
|
mount -s /dev/disk/by-label/${PART_LABEL}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
ret=$?
|
2007-05-02 11:19:43 +02:00
|
|
|
|
2007-05-02 13:31:32 +02:00
|
|
|
else
|
|
|
|
echo "No automatic nodes or attached disks found!"
|
|
|
|
ret=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
eend $ret
|
2007-05-02 11:19:43 +02:00
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2007-05-02 13:31:32 +02:00
|
|
|
NETDEV_GREP="`grep _netdev /etc/mtab`"
|
|
|
|
|
|
|
|
if [ "x${?}" == "x0" ] ; then
|
|
|
|
ebegin "Unmounting all disks with entries in /etc/mtab"
|
|
|
|
|
|
|
|
ISCSI_MOUNTS="`echo ${NETDEV_GREP} | awk '{ print $1; }'`"
|
|
|
|
for ISCSI_MOUNT in "${ISCSI_MOUNTS}" ; do
|
|
|
|
umount ${ISCSI_MOUNT}
|
|
|
|
done
|
|
|
|
|
|
|
|
ret=$?
|
|
|
|
eend $ret
|
|
|
|
fi
|
2007-05-02 11:19:43 +02:00
|
|
|
|
|
|
|
ebegin "Logging out of all nodes"
|
|
|
|
${ADM} -m node -U all
|
|
|
|
ret=$?
|
|
|
|
eend $ret
|
|
|
|
|
|
|
|
ebegin "Stopping ${NAME}"
|
|
|
|
start-stop-daemon --signal HUP --stop --quiet --exec $DAEMON #--pidfile $PID_FILE
|
|
|
|
eend $?
|
|
|
|
|
|
|
|
# ugly, but pid file is not removed by iscsid
|
|
|
|
rm -f $PID_FILE
|
|
|
|
|
|
|
|
do_modules 'Removing iSCSI modules' 'iscsi_tcp scsi_transport_iscsi' '-r'
|
|
|
|
ret=$?
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
opts="${opts} dump"
|
|
|
|
|
|
|
|
dump() {
|
|
|
|
einfo "Starting dump of iscsid database (nodes)"
|
|
|
|
NODELIST="$(iscsiadm -m node | awk -F '[\\[\\]]' '{print $2}')"
|
|
|
|
[ -f ${DUMP_NODE} ] && mv -f ${DUMP_NODE} ${DUMP_NODE}.old
|
|
|
|
for i in $NODELIST ; do
|
|
|
|
echo "# $(iscsiadm -m node | egrep "^\[$i\]")" >>${DUMP_NODE}
|
|
|
|
iscsiadm -m node --record=$i >>${DUMP_NODE}
|
|
|
|
echo >>${DUMP_NODE}
|
|
|
|
done
|
|
|
|
einfo "Starting dump of iscsid database (discovery)"
|
|
|
|
DISCOVERYLIST="$(iscsiadm -m discovery | awk -F '[\\[\\]]' '{print $2}')"
|
|
|
|
[ -f ${DUMP_DISCOVERY} ] && mv -f ${DUMP_DISCOVERY} ${DUMP_DISCOVERY}.old
|
|
|
|
for i in $DISCOVERYLIST ; do
|
|
|
|
echo "# $(iscsiadm -m discovery | egrep "^\[$i\]")" >>${DUMP_DISCOVERY}
|
|
|
|
iscsiadm -m discovery --record=$i >>${DUMP_DISCOVERY}
|
|
|
|
echo >>${DUMP_DISCOVERY}
|
|
|
|
done
|
|
|
|
|
|
|
|
einfo "Config dumped to ${DUMP_DIR}/"
|
|
|
|
}
|