summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-support/tgt/files/tgtd.init
diff options
context:
space:
mode:
authorAmy Fong <amy.fong@windriver.com>2014-03-17 14:14:48 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2014-03-17 15:27:41 -0400
commit9a74961bafabc404f015fc5d8a9da969d263dad3 (patch)
treeedc0caa250166b128c89f606d17373c75e233d26 /meta-openstack/recipes-support/tgt/files/tgtd.init
parent71ef5b7acb5815c678cda0c115e98e6b1d06e1aa (diff)
downloadmeta-cloud-services-9a74961bafabc404f015fc5d8a9da969d263dad3.tar.gz
OpenStack: Add to missing functionality in sysvinit scripts
Add status/reload to sysvinit scripts Modify tgtd to make start/stop work better (borrowed from Debian's implementation) Signed-off-by: Amy Fong <amy.fong@windriver.com> Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'meta-openstack/recipes-support/tgt/files/tgtd.init')
-rw-r--r--meta-openstack/recipes-support/tgt/files/tgtd.init86
1 files changed, 61 insertions, 25 deletions
diff --git a/meta-openstack/recipes-support/tgt/files/tgtd.init b/meta-openstack/recipes-support/tgt/files/tgtd.init
index 3408645..ab91190 100644
--- a/meta-openstack/recipes-support/tgt/files/tgtd.init
+++ b/meta-openstack/recipes-support/tgt/files/tgtd.init
@@ -12,43 +12,73 @@
12 12
13DESC="tgtd" 13DESC="tgtd"
14DAEMON="/usr/sbin/tgtd" 14DAEMON="/usr/sbin/tgtd"
15PIDFILE="/var/run/tgtd.pid" 15TGTD_CONFIG=/etc/tgt/targets.conf
16 16
17start () 17start ()
18{ 18{
19 if [ -e $PIDFILE ]; then
20 PIDDIR=/proc/$(cat $PIDFILE)
21 if [ -d ${PIDDIR} ]; then
22 echo "$DESC already running."
23 exit 1
24 else
25 echo "Removing stale PID file $PIDFILE"
26 rm -f $PIDFILE
27 fi
28 fi
29
30 echo -n "Starting $DESC..." 19 echo -n "Starting $DESC..."
31 20 # Start tgtd first
32 start-stop-daemon --start --quiet --pidfile ${PIDFILE} \ 21 $DAEMON &>/dev/null
33 --make-pidfile --exec ${DAEMON} 22 RETVAL=$?
34 23 if [ "$RETVAL" -ne 0 ]; then
35 if [ $? -eq 0 ]; then
36 echo "done."
37 else
38 echo "failed." 24 echo "failed."
25 exit 1
39 fi 26 fi
27
28 # Put tgtd into "offline" state until all the targets are configured.
29 # We don't want initiators to (re)connect and fail the connection
30 # if it's not ready.
31 tgtadm --op update --mode sys --name State -v offline
32 # Configure the targets.
33 tgt-admin -e -c $TGTD_CONFIG
34 # Put tgtd into "ready" state.
35 tgtadm --op update --mode sys --name State -v ready
36
37 echo "done."
40} 38}
41 39
42stop () 40stop ()
43{ 41{
44 echo -n "Stopping $DESC..." 42 echo -n "Stopping $DESC..."
45 start-stop-daemon --stop --quiet --pidfile $PIDFILE 43
46 if [ $? -eq 0 ]; then 44 # Remove all targets. It only removes targets which are not in use.
47 echo "done." 45 tgt-admin --update ALL -c /dev/null &>/dev/null
48 else 46 # tgtd will exit if all targets were removed
49 echo "failed." 47 tgtadm --op delete --mode system &>/dev/null
48 RETVAL=$?
49 if [ "$RETVAL" -eq 107 ] ; then
50 if [ "$TASK" != "restart" ] ; then
51 exit 1
52 fi
53 elif [ "$RETVAL" -ne 0 ] ; then
54 echo "Some initiators are still connected - could not stop tgtd"
55 exit 2
50 fi 56 fi
51 rm -f $PIDFILE 57 echo -n
58}
59
60reload()
61{
62 echo "Reloading configuration of $DESC" "$NAME"
63 # Update configuration for targets. Only targets which
64 # are not in use will be updated.
65 tgt-admin --update ALL -c $TGTD_CONFIG &>/dev/null
66 RETVAL=$?
67 if [ "$RETVAL" -eq 107 ] ; then
68 echo "tgtd is not running"
69 exit 1
70 fi
71}
72
73status()
74{
75 tgt-admin -s >/dev/null 2>&1
76 RETVAL=$?
77 if [ "$RETVAL" -eq 107 ] ; then
78 echo "tgtd is not running"
79 else
80 echo "tgtd is running"
81 fi
52} 82}
53 83
54case "$1" in 84case "$1" in
@@ -62,6 +92,12 @@ case "$1" in
62 stop 92 stop
63 start 93 start
64 ;; 94 ;;
95 reload)
96 reload
97 ;;
98 status)
99 status
100 ;;
65 *) 101 *)
66 echo "Usage: $0 {start|stop|force-reload|restart}" 102 echo "Usage: $0 {start|stop|force-reload|restart}"
67 exit 1 103 exit 1