📄 rc.iscsi
字号:
#! /bin/sh# chkconfig: 2345 11 20# description: iSCSI daemon# For SuSE, the following information is read by "insserv" program and the# start/stoplinks are installed at appropriate runlevels.# The network interface and logger has to be up for starting iscsi service### BEGIN INIT INFO# Provides: iscsi# Required-Start: $network $syslog# Required-Stop: $network $syslog# Default-Start: 2 3 5# Default-Stop: 0 1 6# Description: Start iSCSI to allow access to remote SCSI devices### END INIT INFOBASEDIR=/PIDFILE=/var/run/iscsid.pid#Timeouts to be used during iscsi shutdownCONNFAILTIMEOUT=30# Increase the maximum TCP window size in Linux (well, socket memory, which is related) to this numberTCP_WINDOW_SIZE=1048576PATH="$BASEDIR/sbin:$BASEDIR/bin:/sbin:/bin:/usr/sbin:/usr/bin:$PATH"export PATHtest -d $BASEDIR || exit 0iscsi_network_boot(){ mtab=/etc/mtab iscsirootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' $mtab) tmp="/dev/inbpdisk" dev=$(echo $tmp |sed -e "s/\//\\\\\//g") partnr=$(echo $iscsirootfs | sed -e "s/$dev//g") tmp=$tmp$partnr if [ ! $tmp = $iscsirootfs ] ; then return 1 else return 0 fi}shutdown_iscsi_hbas(){ for hba in /sys/class/scsi_host/* ; do if [ -f $hba/proc_name ]; then name=`awk '{print $1}' < $hba/proc_name` if [ $name == "iscsi-sfnet" ]; then echo > $hba/shutdown fi fi done}set_connfailtimeout(){ for hba in /sys/class/scsi_host/* ; do if [ -f $hba/proc_name ]; then name=`awk '{print $1}' < $hba/proc_name` if [ $name == "iscsi-sfnet" ]; then if [ -f $hba/connfailtimeout ]; then echo "$CONNFAILTIMEOUT" > $hba/connfailtimeout fi fi fi done}case $1 in start) # Do sanity checks before we start.. if [ ! -e /etc/iscsi.conf ]; then echo echo "Error: configuration file /etc/iscsi.conf is missing!" echo "The iSCSI driver has not been correctly installed and cannot start." echo exit 1 elif [ -s $PIDFILE ] && kill -0 `head -n 1 $PIDFILE` >/dev/null ; then echo "iSCSI daemon already running" echo exit 1 fi grep -Eq '^[^#]' /etc/iscsi.conf if [ $? -ne 0 ] ; then echo "Error: Configuration file is empty, unable to start the driver" echo exit 1 fi if [ ! -f /etc/initiatorname.iscsi ] ; then echo echo "Error: InitiatorName file /etc/initiatorname.iscsi is missing!" echo "The iSCSI driver has not been correctly installed and cannot start." echo exit 1 fi # see if we need to generate a unique iSCSI InitiatorName # this should only happen if the if grep -q "^GenerateName=yes" /etc/initiatorname.iscsi ; then if [ ! -x $BASEDIR/sbin/iscsi-iname ] ; then echo "Error: $BASEDIR/sbin/iscsi-iname does not exist, driver was not successfully installed" exit 1; fi # Generate a unique InitiatorName and save it INAME=`$BASEDIR/sbin/iscsi-iname` if [ "$INAME" != "" ] ; then echo "## DO NOT EDIT OR REMOVE THIS FILE!" > /etc/initiatorname.iscsi echo "## If you remove this file, the iSCSI daemon will not start." >> /etc/initiatorname.iscsi echo "## If you change the InitiatorName, existing access control lists" >> /etc/initiatorname.iscsi echo "## may reject this initiator. The InitiatorName must be unique">> /etc/initiatorname.iscsi echo "## for each iSCSI initiator. Do NOT duplicate iSCSI InitiatorNames." >> /etc/initiatorname.iscsi printf "InitiatorName=$INAME\n" >> /etc/initiatorname.iscsi chmod 600 /etc/initiatorname.iscsi else echo "Error: failed to generate an iSCSI InitiatorName, driver cannot start." echo exit 1; fi fi # make sure there is a valid InitiatorName for the driver if ! grep -q "^InitiatorName=[^ \t\n]" /etc/initiatorname.iscsi ; then echo echo "Error: /etc/initiatorname.iscsi does not contain a valid InitiatorName." echo "The iSCSI driver has not been correctly installed and cannot start." echo exit 1 fi # cycle the old log, since we can't guarantee anything is managing # it, and in any case it's now only used for debugging info. if [ -e /var/log/iscsi.log ] ; then rm -f /var/log/iscsi.log.old mv /var/log/iscsi.log /var/log/iscsi.log.old fi echo "" > /var/log/iscsi.log chmod 0600 /var/log/iscsi.log # Increase the maximum TCP window size to something that will give # reasonable performance for storage networking. Use at least a 1 MB # max. # This only works if we have /proc, but the daemon assumes that anyway, # so there's no point trying to use sysctl. if [ -e /proc/sys/net/core/rmem_max ] ; then RMEM_MAX=`cat /proc/sys/net/core/rmem_max` if [ $RMEM_MAX -lt $TCP_WINDOW_SIZE ] ; then echo "$TCP_WINDOW_SIZE" > /proc/sys/net/core/rmem_max fi fi if [ -e /proc/sys/net/core/wmem_max ] ; then WMEM_MAX=`cat /proc/sys/net/core/wmem_max` if [ $WMEM_MAX -lt $TCP_WINDOW_SIZE ] ; then echo "$TCP_WINDOW_SIZE" > /proc/sys/net/core/wmem_max fi fi if [ -e /proc/sys/net/ipv4/tcp_rmem ] ; then max=`awk '{print $3}' /proc/sys/net/ipv4/tcp_rmem` if [ $max -lt $TCP_WINDOW_SIZE ] ; then min=`awk '{print $1}' /proc/sys/net/ipv4/tcp_rmem` default=`awk '{print $2}' /proc/sys/net/ipv4/tcp_rmem` echo "$min $default $TCP_WINDOW_SIZE" > /proc/sys/net/ipv4/tcp_rmem fi fi if [ -e /proc/sys/net/ipv4/tcp_wmem ] ; then max=`awk '{print $3}' /proc/sys/net/ipv4/tcp_wmem` if [ $max -lt $TCP_WINDOW_SIZE ] ; then min=`awk '{print $1}' /proc/sys/net/ipv4/tcp_wmem` default=`awk '{print $2}' /proc/sys/net/ipv4/tcp_wmem` echo "$min $default $TCP_WINDOW_SIZE" > /proc/sys/net/ipv4/tcp_wmem fi fi # start echo -n "Starting iSCSI: iscsi" KD=/lib/modules/`uname -r`/kernel/drivers/scsi/iscsi-sfnet EM=/lib/modules/`uname -r`/misc/iscsi_sfnet.ko #this will be removed after we provide the kernel patch if [ -d $KD ] ; then /sbin/modprobe iscsi_sfnet elif [ -f $EM ] ; then /sbin/modprobe iscsi_sfnet fi # By default, we try to load the scsi disk driver module. # If SCSI support is in modules, sd_mod won't get loaded # until after a /dev/sd* device is opened. This means no # messages about disks will be logged until a disk device # is opened. Worse, mounting by label won't work, since # it relies on /proc/partitions, which won't get updated # until the SCSI disk driver is loaded, creating a circular # dependency. To work around these problems, we try to load # the disk driver here. If you're not using SCSI disks, # you can comment this out. modprobe sd_mod > /dev/null 2>&1 # Create /dev/iscsictl if [ ! -f /dev/iscsictl ]; then while read major device do if [ "$device" == "iscsictl" ]; then mknod /dev/$device c $major 0 fi done < /proc/devices fi echo -n " iscsid" if [ "$DEBUG_ISCSI" ] ; then if [ -e /proc/sys/kernel/sysrq ] ; then # enable magic SysRq echo "1" > /proc/sys/kernel/sysrq fi iscsid -d $DEBUG_ISCSI else iscsid fi # Required for udev to activate/deactivate devices. echo "/sbin/hotplug" > /proc/sys/kernel/hotplug # Make sure the K*iscsi scripts get called if [ -d /var/lock/subsys ] ; then touch /var/lock/subsys/iscsi fi # if we have an iSCSI fstab, process it if [ -f /etc/fstab.iscsi ] ; then echo -n " fsck/mount" sleep 6 iscsi-mountall fi echo "" ;; stop) # if iSCSI network boot then exit. if iscsi_network_boot ; then echo "Since it is an iSCSI network boot therefore, driver cannot be stopped/restarted" exit 1 fi echo -n "Stopping iSCSI:" # We need a low connfailtimeout so that driver shutdown does not hang set_connfailtimeout; echo -n " sync" sync # unmount all filesystems on iSCSI devices echo -n " umount" iscsi-umountall -t -k echo -n " sync" sync sleep 3 if [ -f $PIDFILE ] ; then echo -n " iscsid" kill -TERM `head -n 1 $PIDFILE` sleep 2 killall $BASEDIR/sbin/iscsid > /dev/null 2>&1 killall iscsid > /dev/null 2>&1 rm -f $PIDFILE fi # shutdown the kernel module shutdown_iscsi_hbas; if grep -q "iscsi_sfnet" /proc/modules ; then rmmod iscsi_sfnet > /dev/null 2>&1 fi # Remove iscsi control device if [ -e /dev/iscsictl ] ; then rm /dev/iscsictl fi if [ -e /var/lock/subsys/iscsi ] ; then rm /var/lock/subsys/iscsi fi echo ;; restart) # if iSCSI network boot then exit. if iscsi_network_boot ; then echo "Since it is an iSCSI network boot therefore, driver cannot be stopped/restarted" exit 1 fi $0 stop $0 start ;; reload) if [ -f $PIDFILE ] ; then kill -HUP `head -n 1 $PIDFILE` fi ;; status) if [ -s $PIDFILE ] && kill -0 `head -n 1 $PIDFILE` >/dev/null ; then echo "iSCSI driver is loaded" else echo "iSCSI driver is not loaded" fi ;; debug1) DEBUG_ISCSI=1 export DEBUG_ISCSI $0 start ;; debug2) DEBUG_ISCSI=2 export DEBUG_ISCSI $0 start ;; debug3) DEBUG_ISCSI=3 export DEBUG_ISCSI $0 start ;; debug4) DEBUG_ISCSI=4 export DEBUG_ISCSI $0 start ;; debug|debug5) DEBUG_ISCSI=5 export DEBUG_ISCSI $0 start ;; debug6) DEBUG_ISCSI=6 export DEBUG_ISCSI $0 start ;; debug7) DEBUG_ISCSI=7 export DEBUG_ISCSI $0 start ;; redebug1) $0 stop $0 debug1 ;; redebug2) $0 stop $0 debug2 ;; redebug3) $0 stop $0 debug3 ;; redebug4) $0 stop $0 debug4 ;; redebug|redebug5) $0 stop $0 debug5 ;; redebug6) $0 stop $0 debug6 ;; redebug7) $0 stop $0 debug ;; *) echo "Usage: /etc/init.d/iscsi { start | stop | restart | status | reload }" ;;esacexit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -