aboutsummaryrefslogtreecommitdiffstats
path: root/main/iscsitarget/ietd.initd
diff options
context:
space:
mode:
Diffstat (limited to 'main/iscsitarget/ietd.initd')
-rw-r--r--main/iscsitarget/ietd.initd106
1 files changed, 106 insertions, 0 deletions
diff --git a/main/iscsitarget/ietd.initd b/main/iscsitarget/ietd.initd
new file mode 100644
index 0000000000..6ea9a4b51e
--- /dev/null
+++ b/main/iscsitarget/ietd.initd
@@ -0,0 +1,106 @@
+#!/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 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: