#!/bin/sh # # /etc/rc.d/rc.iscsi # # Start/stop/restart the iscsi initiator # MP="/mnt/iscsi" # マウントポイント TIP="192.168.0.100" # ターゲットのホストIP TNAME="target0" # ターゲットのボリューム名 ISD=`ps ax|grep iscsid|grep -v grep|wc -l` echo $ISD get_target (){ TGT=`/sbin/iscsiadm -m discovery -t sendtargets \ -p $TIP|grep $TNAME|gawk '{print $2}'` } if [ $ISD != 0 ] ; then get_target fi echo $TGT iscsi_start() { modprobe iscsi-tcp if [ $ISD == 0 ] ; then echo "Staring iscsi" /sbin/iscsid& # sleep 1 fi get_target if [ "$TGT" != "" ] ; then iscsiadm -m node -T $TGT -l sleep 1 echo "mount $MP" mount $MP fi } iscsi_stop() { echo "Stopping iscsi" ISM=`mount|grep $MP|wc -l` if [ $ISM != "0" ] ; then umount $MP iscsiadm -m node -T $TGT -u fi sleep 1 if [ "`ls /sys/class/iscsi_host|wc -l`" != "0" ] ; then echo "still alive iscsi. cant kill iscsid." else echo "kill iscsid" killall iscsid fi } iscsi_restart() { iscsi_stop sleep 2 iscsi_start } case "$1" in 'start') iscsi_start ;; 'stop') iscsi_stop ;; 'restart') iscsi_restart ;; *) # Default is "start", for backwards compatibility with previous # Slackware versions. This may change to a 'usage' error someday. iscsi_start esac