-
Notifications
You must be signed in to change notification settings - Fork 251
/
run.sh
executable file
·130 lines (113 loc) · 3.33 KB
/
run.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
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
#!/bin/bash
##########################################################################################
# 1. The default run.sh and server.yaml are provided mainly for development and demo purpose.
# It is highly recommended to create your own run.sh and server.yaml for production use,
# so that you can fine tune JVM options and customize server configs.
#
# 2. The default run.sh provide an simple but portable way of running Teletraan in background.
# It is highly recommended to use your favorite tools to daemonize it properly, such as
# use start-stop-daemon, init, runsv (from runit), upstart, systemd, and etc.
# Also, use monit, supervisor or other process monitoring tools to monitor your process.
##########################################################################################
# Specify all the defaults
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT_DIR="$(dirname ${DIR})"
TARGET_DIR="${ROOT_DIR}/target"
CP=${ROOT_DIR}/*:${ROOT_DIR}/lib/*:${TARGET_DIR}/classes:${TARGET_DIR}/lib/*
CONFIG_FILE=${ROOT_DIR}/bin/server.yaml
PID_FILE=${HOME}/teletraan.pid
ACTION="run"
JAVA_OPTS="-server -Xmx1024m -Xms1024m \
-verbosegc -Xloggc:/tmp/gc.log -XX:ErrorFile=/tmp/jvm_error.log \
-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintClassHistogram \
-XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+UseParNewGC \
-XX:ConcGCThreads=7 -XX:ParallelGCThreads=7"
JAVA_CMD="java"
if [ "x$JAVA_HOME" != "x" ]; then JAVA_CMD=${JAVA_HOME}/bin/java; fi
display_usage() {
echo -e "Usage: $0 [OPTIONS] [run|start|stop|restart]"
echo -e "\nOPTIONS:"
echo -e " -c/--config Config file, default is ${CONFIG_FILE}"
echo -e " -i/--pid PID file, default is ${PID_FILE}"
echo -e " -p/--class-path Class path, default is ${CP}"
echo -e " -o/--java-opts JVM options, default is ${JAVA_OPTS}"
echo -e "\nACTION:"
echo -e " run Run service in foreground. This is the default action."
echo -e " start Run service in background."
echo -e " stop Stop the service running in background."
echo -e " restart Restart the service running in background."
}
function server_start {
echo "Starting Teletraan server..."
OPTS="${JAVA_OPTS} \
-cp ${CP} \
com.pinterest.teletraan.TeletraanService \
server ${CONFIG_FILE}"
echo $OPTS
if [ "$1" == "FOREGROUND" ]
then
${JAVA_CMD} ${OPTS}
else
${JAVA_CMD} ${OPTS} &
echo $! > ${PID_FILE}
echo "Teletraan server started."
fi
}
function server_stop {
kill -TERM $(cat ${PID_FILE})
rm -fr ${PID_FILE}
echo "Teletraan server stopped."
}
function action {
case "$1" in
run)
server_start "FOREGROUND"
;;
start)
server_start "BACKGROUND"
;;
stop)
server_stop
;;
restart)
server_stop
server_start
;;
esac
}
while [[ $# > 0 ]]
do
key="$1"
case $key in
-c|--config)
CONFIG_FILE="$2"
shift # past argument
;;
-p|--class-path)
CP="$2"
shift # past argument
;;
-o|--java-opts)
JAVA_OPTS="$2"
shift # past argument
;;
-p|--pid)
PID_FILE="$2"
shift # past argument
;;
-h|--help)
display_usage
exit 0
;;
run|start|stop|restart)
ACTION="$1"
;;
*)
display_usage
exit 1
;;
esac
shift # past argument or value
done
action ${ACTION}
exit 0