File: tarantool_box

package info (click to toggle)
tarantool 1.5.2.20.g5f5d924-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 26,568 kB
  • ctags: 18,697
  • sloc: ansic: 109,092; sh: 21,312; cpp: 20,633; xml: 9,666; asm: 2,488; python: 2,195; java: 1,759; perl: 1,002; makefile: 679
file content (129 lines) | stat: -rw-r--r-- 2,867 bytes parent folder | download | duplicates (2)
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
#!/bin/bash

#  /etc/rc.d/init.d/tarantool_box
#
# chkconfig: 2345 99 99
# description: tarantool_box
# processname: tarantool_box

. /etc/init.d/functions

RETVAL=0
# If we're running from sysinit, the basename is
# prefixed with a prefix like:
# /etc/rc3.d/S99tarantool_box1.1 -> ../init.d/tarantool_box1.1
# Filter S99 out.
INST=$(basename $0 | sed 's/^[SK][0-9]\{2\}//g')
export PIDFILE="/var/${INST}/box.pid"
export WRAP_PIDFILE="/var/${INST}/wrapper.pid"
export OPTIONS=""

# This script is normally invoked via a symlink.
# An own symlink is created for each instance.
# E.g., in case of 4 instances, there are symlinks
# tarantool0, tarantool1, tarantool2, tarantool3.
# If, for some reason, this script is invoked not via
# a symlink, do nothing.
#
if [ "${INST}" == "tarantool_box" ]
then
        echo_failure
        echo
        exit
fi

checkactive() {
        if [ -f ${WRAP_PIDFILE} ]
        then
                ps -p $(cat ${WRAP_PIDFILE}) >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                        echo -n "(instance is active)"
                        echo_failure
                        exit 1
                fi
        fi
        if [ -f ${PIDFILE} ]
        then
                ps -p $(cat ${PIDFILE}) >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                        echo -n "(instance is active)"
                        echo_failure
                        exit 1
                fi
        fi
}

start() {
        echo -n $"Starting ${INST}: "
        checkactive
        /usr/bin/${INST}.sh ${OPTIONS} >> /var/${INST}/logs/init.log 2>&1
        RETVAL=${?}
        if [ ${RETVAL} -eq 0 ]
        then
                echo_success
        else
                echo_failure
        fi
        echo
        return ${RETVAL}
}

terminate() {
	timeout=${1}
	pid=${2}
	kill ${pid} >/dev/null 2>&1
	sleep ${timeout}
	ps -p ${pid} >/dev/null 2>&1
	if [ $? -eq 0 ]; then
		sleep 10;
		ps -p ${pid} >/dev/null 2>&1
		if [ $? -eq 0 ]; then
			kill -9 ${pid}
			sleep 3
			ps -p 0 ${pid} >/dev/null 2>&1
			if [ $? -eq 0 ]; then
                		echo_failure
				exit 1
			fi
		fi 
	fi
}

stop() {
        echo -n $"Stopping $INST: "
        if [ -f ${WRAP_PIDFILE} ]
        then
		terminate 1 $(cat ${WRAP_PIDFILE})
                rm -f ${WRAP_PIDFILE} >/dev/null 2>&1
        fi
        if [ -f ${PIDFILE} ]
        then
		terminate 3 $(cat ${PIDFILE})
                rm -f ${PIDFILE} >/dev/null 2>&1
        fi
        echo_success
        echo
        return ${RETVAL}
}

restart() {
        stop
        start
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                restart
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart}"
                RETVAL=1
esac

exit ${RETVAL}