From owner-freebsd-scsi@FreeBSD.ORG Tue May 7 07:53:30 2013 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C97D5875 for ; Tue, 7 May 2013 07:53:30 +0000 (UTC) (envelope-from danny@cs.huji.ac.il) Received: from kabab.cs.huji.ac.il (kabab.cs.huji.ac.il [132.65.16.84]) by mx1.freebsd.org (Postfix) with ESMTP id 83C2D697 for ; Tue, 7 May 2013 07:53:30 +0000 (UTC) Received: from pampa.cs.huji.ac.il ([132.65.80.32]) by kabab.cs.huji.ac.il with esmtp id 1UZci4-000LXF-MW; Tue, 07 May 2013 10:53:16 +0300 X-Mailer: exmh version 2.7.2 01/07/2005 with nmh-1.3 To: David Newman Subject: Re: running iscontrol at boot time In-reply-to: <51868972.804@networktest.com> References: <51868972.804@networktest.com> Comments: In-reply-to David Newman message dated "Sun, 05 May 2013 09:31:46 -0700." Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 07 May 2013 10:53:16 +0300 From: Daniel Braniss Message-ID: Cc: freebsd-scsi@freebsd.org X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 May 2013 07:53:30 -0000 Hi David, I'm attaching a script, it was last tested on 8.2, but should work :-) /etc/rc.d/iscsi (probably should be remnamed iscsi_initiator) #!/bin/sh # PROVIDE: iscsi # REQUIRE: NETWORKING # BEFORE: DAEMON # KEYWORD: nojail shutdown # # Add the following lines to /etc/rc.conf to enable iscsi: # # iscsi_enable="YES" # iscsi_fstab="/etc/fstab.iscsi" . /etc/rc.subr . /cs/share/etc/rc.subr name=iscsi rcvar=`set_rcvar` command=/sbin/iscontrol iscsi_enable=${iscsi_enable:-"NO"} iscsi_fstab=${iscsi_fstab:-"/etc/fstab.iscsi"} iscsi_exports=${iscsi_exports:-"/etc/exports.iscsi"} iscsi_debug=${iscsi_debug:-0} start_cmd="iscsi_start" faststop_cmp="iscsi_stop" stop_cmd="iscsi_stop" start_precmd="iscontrol_precmd" iscontrol_prog=${iscontrol_prog:-"iscontrol"} iscontrol_log=${iscontrol_log:-"/var/log/$iscontrol_prog"} iscontrol_syslog=${iscontrol_syslog:-"644 3 100 * JC"} iscontrol_precmd() { setup_syslog "$iscontrol_prog" "$iscontrol_log" "$iscontrol_syslog" } iscsi_wait() { dev=$1 trap "echo 'wait loop cancelled'; exit 1" 2 count=0 while true; do if [ -c $dev ]; then break; fi if [ $count -eq 0 ]; then echo -n Waiting for ${dev}': ' fi count=$((${count} + 1)) if [ $count -eq 6 ]; then echo " Failed for dev=$dev" return 0 break fi echo -n '.' sleep 5; done echo "$dev ok." return 1 } iscsi_start() { local file type opt t1 t2 # # load needed modules for m in iscsi_initiator geom_label; do kldstat -qm $m || kldload $m done sysctl debug.iscsi_initiator=$iscsi_debug # # start iscontrol for each target if [ -n "${iscsi_targets}" ]; then for target in ${iscsi_targets}; do ${command} ${rc_flags} -n ${target} done fi if [ -f "${iscsi_fstab}" ]; then while read spec file type opt t1 t2 do case ${spec} in \#*|'') ;; *) if iscsi_wait ${spec}; then break; fi echo type=$type spec=$spec file=$file fsck -p ${spec} && mkdir -p ${file} && mount ${spec} ${file} chmod 755 ${file} ;; esac done < ${iscsi_fstab} fi if [ -f "${iscsi_exports}" ]; then cat ${iscsi_exports} >> /etc/exports #/etc/rc.d/mountd reload kill -1 `cat /var/run/mountd.pid` fi if checkyesno zfs_enable; then if checkyesno iscsi_zfs; then sleep 4 zpool import -d /dev/label -a # presumably we can ignore zfs mount -a share -a and swapon # some zfs dataset may be exported "legacy", so hup mountd kill -1 `cat /var/run/mountd.pid` fi fi } iscsi_stop() { echo 'iscsi stopping' while read spec file type opt t1 t2 do case ${spec} in \#*|'') ;; *) echo iscsi: umount $spec umount -fv $spec ;; esac done < ${iscsi_fstab} } load_rc_config $name run_rc_command "$1"