#!/bin/sh
#
# /etc/init.d/iscsitarget
#
### BEGIN INIT INFO
# Provides:          iscsitarget
# Required-Start:    $remote_fs $network
# Should-Start:
# Required-Stop:     $remote_fs $network
# Should-Stop:
# Default-Start:     3 5
# Default-Stop:      
# Short-Description: iSCSI target daemon
# Description:
# Script to start and stop the iSCSI target daemon
### END INIT INFO

#
#
# pidfile: /var/run/ietd.pid
# config:  /etc/ietd.conf

DAEMON=/usr/sbin/ietd
PIDFILE=/var/run/ietd.pid
CONFIG=/etc/ietd.conf

# Source LSB init functions
. /etc/rc.status

rc_reset

PATH=/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
  start)
	echo -n "Starting iSCSI target service: "
	modprobe -q crc32c
	modprobe iscsi_trgt
	startproc -p $PIDFILE $DAEMON
	rc_status -v
        ;;
  stop)
	echo -n "Stopping iSCSI target service: "
	ietadm --op delete >/dev/null 2>/dev/null
	killproc -p $PIDFILE -TERM $DAEMON
	rc_status
	modprobe -r iscsi_trgt 2>/dev/null || /bin/true
	modprobe -r crc32c 2>/dev/null || /bin/true
	rc_status -v
        ;;
  restart|reload)
        $0 stop
        $0 start
        ;;
  status)
	echo -n "Checking for iSCSI target service"
	checkproc -p $PIDFILE $DAEMON
	rc_status -v
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
esac
rc_exit
