summaryrefslogtreecommitdiffstats
path: root/main/iscsitarget/ietd.initd
blob: ac315609e6a8abb128b87acf5c593a93a0d0f640 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/sbin/runscript
# Copyright 1999-2008 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/sys-block/iscsitarget/files/ietd-init.d-2,v 1.1 2008/07/18 16:03:38 flameeyes Exp $

MEM_SIZE=1048576
DAEMON=/usr/sbin/ietd
CONFIG_FILE=/etc/ietd.conf
PID_FILE=/var/run/iscsi_trgt.pid
NAME="iSCSI Enterprise Target"

ARGS=""
[ -n "$USER" ] && ARGS="${ARGS} --uid=${USER}"
[ -n "$GROUP" ] && ARGS="${ARGS} --gid=${GROUP}"
[ -n "$ISNS" ] && ARGS="${ARGS} --isns=${ISNS}"
[ -n "$PORT" ] && ARGS="${ARGS} --port=${PORT}"
[ -n "$ADDRESS" ] && ARGS="${ARGS} --address=${ADDRESS}"
[ -n "$DEBUGLEVEL" ] && ARGS="${ARGS} --debug=${DEBUGLEVEL}"

depend() {
	use net
	after firewall modules
}

checkconfig() {
	if [ ! -f $CONFIG_FILE ]; then
		eerror "Config file $CONFIG_FILE does not exist!"
		return 1
	fi
	if [ -z "$DISABLE_MEMORY_WARNINGS" ]; then
		check_memsize
	fi
}

check_memsize() {
	local wr md sysctl_key v k
	for wr in r w; do
		for md in max default; do
			sysctl_key="net.core.${wr}mem_${md}"
			v="$(sysctl -n ${sysctl_key})"
			if [ "${v}" -lt "${MEM_SIZE}" ]; then
				ewarn "$sysctl_key ($v) is lower than recommended ${MEM_SIZE}"
			fi
		done
	done
	for wr in "" r w; do
		sysctl_key="net.ipv4.tcp_${wr}mem"
		set -- $(sysctl -n ${sysctl_key})
		for k in min default max ; do
			if [ "${1}" -lt "${MEM_SIZE}" ]; then
				ewarn "$sysctl_key:$k (${1}) is lower than recommended ${MEM_SIZE}"
			fi
			shift
		done
	done
}

do_modules() {
	msg="$1"
	shift
	modules="$1"
	shift
	opts="$@"
	for m in ${modules}; do
		ebegin "${msg} - ${m}"
		modprobe ${opts} $m
		ret=$?
		eend $ret
		[ $ret -ne 0 ] && return $ret
	done
	return 0
}

start() {
	checkconfig || return 1
	do_modules 'Loading iSCSI-Target modules' 'iscsi_trgt'
	ebegin "Starting ${NAME}"
	start-stop-daemon --start --exec $DAEMON --quiet -- ${ARGS}
	eend $?
}

stop() {
	ebegin "Removing ${NAME} devices"
	# ugly, but ietadm does not allways provides correct exit values
	RETURN="$(ietadm --op delete 2>&1)"
	RETVAL=$?
	if [ $RETVAL -eq 0 ] && [ "$RETURN" != "something wrong" ] ; then
		eend 0
	else
		eend 1
		eerror "ietadm failed - $RETURN"
		return 1
	fi

	ebegin "Stopping ${NAME}"
	start-stop-daemon --stop --quiet --exec $DAEMON --pidfile $PID_FILE
	ret=$?
	eend $ret
	[ $ret -ne 0 ] && return 1

	# ugly, but pid file is not removed by ietd
	rm -f $PID_FILE
	# do_modules 'Removing iSCSI-Target modules' 'iscsi_trgt' '-r'
	return $?
}

# vim: tw=72: