blob: 52d98c39a2918b790e237dbf2e38a71131d4a08a (
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
|
#!/bin/sh
### BEGIN INIT INFO
# Provides: tgtd
# Required-Start: $remote_fs $network $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: SCSI target daemon
# Description: Linux SCSI target framework (tgt)
### END INIT INFO
DESC="tgtd"
DAEMON="/usr/sbin/tgtd"
TGTD_CONFIG=/etc/tgt/targets.conf
start ()
{
echo -n "Starting $DESC..."
# Ensure service isn't running
tgt-admin -s >/dev/null 2>&1
RETVAL=$?
if [ "$RETVAL" -ne 107 ] ; then
echo "$DESC is already running."
exit 1
fi
# Start tgtd first
$DAEMON &>/dev/null
RETVAL=$?
if [ "$RETVAL" -ne 0 ]; then
echo "failed."
exit 1
fi
# Put tgtd into "offline" state until all the targets are configured.
# We don't want initiators to (re)connect and fail the connection
# if it's not ready.
tgtadm --op update --mode sys --name State -v offline
# Configure the targets.
tgt-admin -e -c $TGTD_CONFIG
# Put tgtd into "ready" state.
tgtadm --op update --mode sys --name State -v ready
echo "done."
}
stop ()
{
echo -n "Stopping $DESC..."
# Remove all targets. It only removes targets which are not in use.
tgt-admin --update ALL -c /dev/null &>/dev/null
# tgtd will exit if all targets were removed
tgtadm --op delete --mode system &>/dev/null
RETVAL=$?
if [ "$RETVAL" -eq 107 ] ; then
if [ "$TASK" != "restart" ] ; then
exit 1
fi
elif [ "$RETVAL" -ne 0 ] ; then
echo "Some initiators are still connected - could not stop tgtd"
exit 2
fi
echo -n
}
reload()
{
echo "Reloading configuration of $DESC" "$NAME"
# Update configuration for targets. Only targets which
# are not in use will be updated.
tgt-admin --update ALL -c $TGTD_CONFIG &>/dev/null
RETVAL=$?
if [ "$RETVAL" -eq 107 ] ; then
echo "tgtd is not running"
exit 1
fi
}
status()
{
tgt-admin -s >/dev/null 2>&1
RETVAL=$?
if [ "$RETVAL" -eq 107 ] ; then
echo "tgtd is not running"
else
echo "tgtd is running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
stop
start
;;
reload)
reload
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|force-reload|restart|status|reload}"
exit 1
;;
esac
exit 0
|