forked from apache/incubator-teaclave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.sh
executable file
·100 lines (95 loc) · 2.44 KB
/
service.sh
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
#!/bin/bash
if [ -z "${MESATEE_BIN}" ]; then
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
MESATEE_BIN=${SCRIPT_DIR}/bin
echo "env var MESATEE_BIN is not set, use ${MESATEE_BIN}"
fi
if [ -z "${MESATEE_CFG_DIR}" ]; then
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
MESATEE_CFG_DIR=$SCRIPT_DIR
echo "env var MESATEE_CFG_DIR is not set, use ${MESATEE_CFG_DIR}"
fi
export MESATEE_CFG_DIR
get_stdout_file() {
echo -n "/tmp/$1.log"
}
get_stderr_file() {
echo -n "/tmp/$1.err"
}
get_pid_file() {
echo -n "/tmp/$1.pid"
}
get_pid() {
pid_file=`get_pid_file $1`
cat "$pid_file"
}
is_running() {
pid_file=`get_pid_file $1`
[ -f "$pid_file" ] && ps -p `get_pid $1` > /dev/null 2>&1
}
case "$1" in
start)
for name in tms tdfs fns kms ; do
if is_running $name; then
echo "$name already started";
exit 1
fi
done
cd $MESATEE_BIN
for name in tms tdfs fns kms ; do
echo "Starting $name"
stdout_log=`get_stdout_file $name`
stderr_log=`get_stderr_file $name`
pid_file=`get_pid_file $name`
./$name >> "$stdout_log" 2>> "$stderr_log" &
echo $! > "$pid_file"
if ! is_running $name; then
echo "Unable to start $name, see $stdout_log and $stderr_log"
exit 1
fi
done
;;
stop)
for name in tms tdfs fns kms ; do
if is_running $name; then
echo "Stopping $name.."
kill `get_pid $name`
else
echo "$name not running"
fi
done
for name in tms tdfs fns kms ; do
for i in 1 2 3 4 5 6 7 8 9 10; do
if ! is_running $name; then
break
fi
echo -n "."
sleep 1
done
if is_running $name; then
echo "Not stopped $name; may still be shutting down or shutdown may have failed"
else
echo "Stopped $name"
pid_file=`get_pid_file $name`
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
done
;;
restart)
bash $0 stop
for name in tms tdfs fns kms ; do
if is_running $name; then
echo "Unable to stop $name, will not attempt to start"
exit 1
fi
done
bash $0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0