aboutsummaryrefslogtreecommitdiff
path: root/network/iscsitarget/rc.iscsi-target.new
blob: acfbe38c85451fe91c6013512b0dced25c09fb32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash

# Written by Thales A. Tsailas <ttsailas@enforcingit.com>
# Init script for the iSCSI Enterprise Target.
# http://iscsitarget.sourceforge.net/
# For Slackware Linux 

PATH=/sbin:/bin:/usr/sbin:/usr/bin
CONF=/etc/iet/ietd.conf
PID=$(pidof ietd)

RETVAL=0

start()
{
	# Load necessary modules 
	if [ ! "$PID" = '' ]; then
	  echo -en "iSCSI enterprise target is already running\n"
	else 
 	  echo -en "Loading iSCSI enterprise target module\n"
	  modprobe iscsi_trgt
	echo -en "Starting iSCSI enterprise target..."
	  /usr/sbin/ietd -c $CONF 
	  sleep 1

	    if [ $RETVAL = "0" ]; then
                echo -en "done.\n"
            else
                echo -en "failed.\n"
                exit $RETVAL
            fi
	fi

}

stop()
{
	if [ "$PID" = '' ]; then
	   echo -en "iSCSI enterprise target is not running\n"
	else 
    	   echo -en "Stoping iSCSI enterprise target...\n"
	   ietadm --op delete
	   kill -9 $PID
	   echo -en "Unloading iSCSI enterprise target modules"
	   modprobe -r iscsi_trgt
	   sleep 1
	     if [ $RETVAL = "0" ]; then
                echo -en "done.\n"
             else
                echo -en "failed.\n"
                exit $RETVAL
             fi
	fi


}

status()
{ 	
	if [ "$PID" = '' ]; then
	   echo -en "iSCSI enterprise target is not running\n"
	else 
	   echo -en "iSCSI enterprise target is running with pid: \033[1m$PID\e[0m\n"	
	   echo -en "Available targets:\n"	
	   cat /proc/net/iet/session
	fi

}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	status) 
		status
		;;
	*)
		echo "Usage: {start|stop|restart|status}" >&2
		exit 1
		;;
esac

exit 0