File iscsitarget.init of Package iscsitarget

#!/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

CONFIG=/etc/iet/ietd.conf
PIDFILE=/var/run/ietd.pid

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
DAEMON=/usr/sbin/ietd
test -x $DAEMON || { echo "$DAEMON not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
SYSCONFIG=/etc/sysconfig/ietd
test -r $SYSCONFIG || { echo "$SYSCONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Read config   
. $SYSCONFIG

# some defaults
OPTS=${IETD_OPTS:=""}

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

# Reset status of this service
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
	## Start daemon with startproc(8). If this fails
	## the return value is set appropriately by startproc.
	/sbin/startproc -p $PIDFILE $DAEMON "$OPTS"

	# Remember status and be verbose
	rc_status -v
        ;;
    stop)
	echo -n "Stopping iSCSI target service: "
	## Stop daemon with killproc(8) and if this fails
	## killproc sets the return value according to LSB.
	ietadm --op delete >/dev/null 2>/dev/null
	/sbin/killproc -p $PIDFILE -TERM $DAEMON
	modprobe -r iscsi_trgt 2>/dev/null
	RETVAL=$?
	modprobe -r crc32c 2>/dev/null
	if [ $RETVAL != "0" ]; then
		rc_failed
	fi

	# Remember status and be verbose
	rc_status -v
        ;;
    restart|reload)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
        $0 stop
        $0 start

	# Remember status and be quiet
	rc_status
        ;;
    status)
	echo -n "Checking for iSCSI target service"
	## Check status with checkproc(8), if process is running
	## checkproc will return with exit status 0.
	/sbin/checkproc -p $PIDFILE $DAEMON

	# Remember status and be verbose
	rc_status -v
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
esac
rc_exit
openSUSE Build Service is sponsored by