aboutsummaryrefslogtreecommitdiffstats
path: root/main/open-iscsi/iscsid.initd
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2014-07-08 06:29:45 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2014-07-08 06:53:20 +0000
commit991001c6f9ccf4f57efd4acff85e30801b1d785d (patch)
tree8bb0cece92da03878c53747d9822fc18f43fd1f9 /main/open-iscsi/iscsid.initd
parent7d7811aa6295c3373d5cddd0cdffaa55293855c2 (diff)
downloadaports-991001c6f9ccf4f57efd4acff85e30801b1d785d.tar.gz
aports-991001c6f9ccf4f57efd4acff85e30801b1d785d.tar.bz2
aports-991001c6f9ccf4f57efd4acff85e30801b1d785d.tar.xz
Revert "main/open-iscsi: removed"
we still need open-iscsi for the initiator This reverts commit 570661a829deb7f4de4b62e5379a424acb2ed9e2.
Diffstat (limited to 'main/open-iscsi/iscsid.initd')
-rw-r--r--main/open-iscsi/iscsid.initd128
1 files changed, 128 insertions, 0 deletions
diff --git a/main/open-iscsi/iscsid.initd b/main/open-iscsi/iscsid.initd
new file mode 100644
index 0000000000..f7d0a26289
--- /dev/null
+++ b/main/open-iscsi/iscsid.initd
@@ -0,0 +1,128 @@
+#!/sbin/runscript
+
+extra_started_commands="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() {
+ local ret=
+ stoptargets
+ ebegin "Stopping ${SVCNAME}"
+ start-stop-daemon --signal HUP --stop --quiet --exec /usr/sbin/iscsid #--pidfile $PID_FILE
+ ret=$?
+ eend $ret
+
+ # ugly, but pid file is not removed by iscsid
+ rm -f $PID_FILE
+ return $ret
+}
+
+starttargets() {
+ ebegin "Setting up iSCSI targets"
+ /usr/bin/iscsiadm -m node --loginall=automatic
+ ret=$?
+ #Don't report error when no targets are configured
+ if [ "$ret" -eq "21" ]; then
+ ret="0"
+ fi
+ 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
+}