From aa790e1c40c36c106884182c9fe15dabad77177d Mon Sep 17 00:00:00 2001 From: Leonardo Arena Date: Fri, 23 Apr 2010 13:04:25 +0000 Subject: testing/open-iscsi: init script busybox compatibility fix --- testing/open-iscsi/iscsid-2.0.871-r1.init.d | 127 ---------------------------- testing/open-iscsi/iscsid.initd | 124 +++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 127 deletions(-) delete mode 100644 testing/open-iscsi/iscsid-2.0.871-r1.init.d create mode 100644 testing/open-iscsi/iscsid.initd diff --git a/testing/open-iscsi/iscsid-2.0.871-r1.init.d b/testing/open-iscsi/iscsid-2.0.871-r1.init.d deleted file mode 100644 index 060eb9b59..000000000 --- a/testing/open-iscsi/iscsid-2.0.871-r1.init.d +++ /dev/null @@ -1,127 +0,0 @@ -#!/sbin/runscript -# Copyright 1999-2008 Gentoo Technologies, Inc. -# Distributed under the terms of the GNU General Public License, v2 or later -# $Header: /var/www/viewcvs.gentoo.org/raw_cvs/gentoo-x86/sys-block/open-iscsi/files/iscsid-2.0.871-r1.init.d,v 1.1 2009/11/12 09:29:48 robbat2 Exp $ - -opts="${opts} starttargets stoptargets restarttargets" - -depend() { - after modules - use net -} - -checkconfig() { - if [ ! -e /etc/conf.d/${SVCNAME} ]; then - eerror "Config file /etc/conf.d/${SVCNAME} does not exist!" - return 1 - fi - if [ ! -e "${CONFIG_FILE}" ]; then - eerror "Config file ${CONFIG_FILE} does not exist!" - return 1 - fi - if [ ! -e ${INITIATORNAME_FILE} ] || [ ! "$(grep "^InitiatorName=iqn\." ${INITIATORNAME_FILE})" ]; then - ewarn "${INITIATORNAME_FILE} should contain a string with your initiatior name." - IQN=iqn.$(date +%Y-%m).$(hostname -f | awk 'BEGIN { FS=".";}{x=NF; while (x>0) {printf $x ;x--; if (x>0) printf ".";} print ""}'):openiscsi - IQN=${IQN}-$(echo ${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM} | md5sum | sed -e "s/\(.*\) -/\1/g" -e 's/ //g') - ebegin "Creating InitiatorName ${IQN} in ${INITIATORNAME_FILE}" - echo "InitiatorName=${IQN}" >> "${INITIATORNAME_FILE}" - eend $? - fi -} - -do_modules() { - msg="$1" - shift - modules="${1}" - shift - modopts="$@" - for m in ${modules} - do - if [ -n "$(modprobe -l | grep ${m})" ] - then - ebegin "${msg} ${m}" - modprobe ${modopts} ${m} - ret=$? - eend ${ret} - if [ ${ret} -ne 0 ]; then - return ${ret} - fi - else - ebegin "${msg} ${m}: not found" - return 1 - fi - done - return 0 -} - -start() { - ebegin "Checking open-iSCSI configuration" - checkconfig - ret=$? - if [ $ret -ne 0 ]; then - eend 1 - return 1 - fi - ebegin "Loading iSCSI modules" - do_modules 'Loading' 'libiscsi scsi_transport_iscsi iscsi_tcp' - ret=$? - if [ $ret -ne 0 ]; then - eend 1 - return 1 - fi - - ebegin "Starting ${SVCNAME}" - start-stop-daemon --start --quiet --exec /usr/sbin/iscsid -- ${OPTS} - ret=$? - if [ $ret -ne 0 ]; then - eend $? - return $? - fi - - # Start automatic targets when iscsid is started - if [ "${AUTOSTARTTARGETS}" = "yes" ]; then - starttargets - return $? - fi - return 0 -} - -stop() { - stoptargets - ebegin "Stopping ${SVCNAME}" - start-stop-daemon --signal HUP --stop --quiet --exec /usr/sbin/iscsid #--pidfile $PID_FILE - eend $? - - # ugly, but pid file is not removed by iscsid - rm -f $PID_FILE - - do_modules 'Removing iSCSI modules' 'iscsi_tcp scsi_transport_iscsi libiscsi' '-r' - eend $? -} - -starttargets() { - ebegin "Setting up iSCSI targets" - /usr/bin/iscsiadm -m node --loginall=automatic - ret=$? - eend $ret - return $ret -} - -stoptargets() { - ebegin "Disconnecting iSCSI targets" - sync - /usr/bin/iscsiadm -m node --logoutall=all - ret=$? - eend $ret - return $ret -} - -restarttargets() { - stoptargets - starttargets -} - -status() { - ebegin "Showing current active iSCSI sessions" - /usr/bin/iscsiadm -m session -} diff --git a/testing/open-iscsi/iscsid.initd b/testing/open-iscsi/iscsid.initd new file mode 100644 index 000000000..572b0a6ae --- /dev/null +++ b/testing/open-iscsi/iscsid.initd @@ -0,0 +1,124 @@ +#!/sbin/runscript + +opts="${opts} starttargets stoptargets restarttargets" + +depend() { + after modules + use net +} + +checkconfig() { + if [ ! -e /etc/conf.d/${SVCNAME} ]; then + eerror "Config file /etc/conf.d/${SVCNAME} does not exist!" + return 1 + fi + if [ ! -e "${CONFIG_FILE}" ]; then + eerror "Config file ${CONFIG_FILE} does not exist!" + return 1 + fi + if [ ! -e ${INITIATORNAME_FILE} ] || [ ! "$(grep "^InitiatorName=iqn\." ${INITIATORNAME_FILE})" ]; then + ewarn "${INITIATORNAME_FILE} should contain a string with your initiatior name." + IQN=iqn.$(date +%Y-%m).$(hostname -f | awk 'BEGIN { FS=".";}{x=NF; while (x>0) {printf $x ;x--; if (x>0) printf ".";} print ""}'):openiscsi + IQN=${IQN}-$(echo ${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM} | md5sum | sed -e "s/\(.*\) -/\1/g" -e 's/ //g') + ebegin "Creating InitiatorName ${IQN} in ${INITIATORNAME_FILE}" + echo "InitiatorName=${IQN}" >> "${INITIATORNAME_FILE}" + eend $? + fi +} + +do_modules() { + msg="$1" + shift + modules="${1}" + shift + modopts="$@" + for m in ${modules} + do + if [ -n "$(find /lib/modules/`uname -r` | grep ${m})" ] + then + ebegin "${msg} ${m}" + modprobe ${modopts} ${m} + ret=$? + eend ${ret} + if [ ${ret} -ne 0 ]; then + return ${ret} + fi + else + ebegin "${msg} ${m}: not found" + return 1 + fi + done + return 0 +} + +start() { + ebegin "Checking open-iSCSI configuration" + checkconfig + ret=$? + if [ $ret -ne 0 ]; then + eend 1 + return 1 + fi + ebegin "Loading iSCSI modules" + do_modules 'Loading' 'libiscsi scsi_transport_iscsi iscsi_tcp' + ret=$? + if [ $ret -ne 0 ]; then + eend 1 + return 1 + fi + + ebegin "Starting ${SVCNAME}" + start-stop-daemon --start --quiet --exec /usr/sbin/iscsid -- ${OPTS} + ret=$? + if [ $ret -ne 0 ]; then + eend $? + return $? + fi + + # Start automatic targets when iscsid is started + if [ "${AUTOSTARTTARGETS}" = "yes" ]; then + starttargets + return $? + fi + return 0 +} + +stop() { + stoptargets + ebegin "Stopping ${SVCNAME}" + start-stop-daemon --signal HUP --stop --quiet --exec /usr/sbin/iscsid #--pidfile $PID_FILE + eend $? + + # ugly, but pid file is not removed by iscsid + rm -f $PID_FILE + + do_modules 'Removing iSCSI modules' 'iscsi_tcp scsi_transport_iscsi libiscsi' '-r' + eend $? +} + +starttargets() { + ebegin "Setting up iSCSI targets" + /usr/bin/iscsiadm -m node --loginall=automatic + ret=$? + eend $ret + return $ret +} + +stoptargets() { + ebegin "Disconnecting iSCSI targets" + sync + /usr/bin/iscsiadm -m node --logoutall=all + ret=$? + eend $ret + return $ret +} + +restarttargets() { + stoptargets + starttargets +} + +status() { + ebegin "Showing current active iSCSI sessions" + /usr/bin/iscsiadm -m session +} -- cgit v1.2.3