blob: 597d0804feb39eff9cb64464c5a880c071bea8db (
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
opts="${opts} starttargets stoptargets restarttargets"
depend() {
after modules
use net
}
PIDFILE=${PIDFILE:-/var/run/${SVCNAME}.pid}
BINARY="/usr/sbin/iscsid"
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 modprobe --show --quiet "${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 ${BINARY} -- ${OPTS}
ret=$?
if [ $ret -ne 0 ]; then
eend $?
return $?
fi
# Start automatic targets when iscsid is started
if [ "${AUTOSTARTTARGETS}" = "yes" ]; then
starttargets
ret=$?
if [ "${AUTOSTART}" = "strict" ] && [ $ret -ne 0 ]; then
stop
return $ret
fi
fi
return 0
}
stop() {
stoptargets
ebegin "Stopping ${SVCNAME}"
start-stop-daemon --stop --quiet --exec ${BINARY} --pidfile ${PIDFILE}
eend $?
do_modules 'Removing iSCSI modules' 'iscsi_tcp scsi_transport_iscsi libiscsi' '-r'
eend $?
}
starttargets() {
ebegin "Setting up iSCSI targets"
/usr/sbin/iscsiadm -m node --loginall=automatic
ret=$?
eend $ret
return $ret
}
stoptargets() {
ebegin "Disconnecting iSCSI targets"
sync
/usr/sbin/iscsiadm -m node --logoutall=all
ret=$?
eend $ret
return $ret
}
restarttargets() {
stoptargets
starttargets
}
status() {
ebegin "Showing current active iSCSI sessions"
/usr/sbin/iscsiadm -m session
}
|