-
Notifications
You must be signed in to change notification settings - Fork 7
/
runServer.sh
executable file
·76 lines (66 loc) · 2.32 KB
/
runServer.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
#!/bin/sh
#
# How To:
# All these actions require that you ran 'mvn package' successfully.
#
# * start server (LAN mode):
# > ./runServer.sh
#
# * start server (normal mode, using a database):
# > FULL_CP=1 ./runServer.sh --database
#
# * start server (debug mode):
# > DBG_PORT=7333 FULL_CP=1 ./runServer.sh
#
# * start server (daemon mode):
# > ./runServer.sh --daemon
#
# * stop server:
# press [Ctrl]+[C]
#
# * stop server (daemon mode):
# > kill $(cat server.pid)
#
PID_FILE=server.pid
# move to the dir containing this script
cd $(dirname $0)
#MY_JAR_BARE=$(ls target/original-springls*)
MY_JAR_BASE=$(ls target/springls*stand-alone.jar)
MY_DEPENDENCY_CP="target/dependency/*"
# use this line for old JDKs
#MY_DEPENDENCY_CP=$(ls -1 target/dependency/*.jar | awk 'BEGIN { cp="" } { if (cp != "") {cp = cp ":"} cp = cp $1 } END { print(cp) }')
if [ ${FULL_CP} ]; then
MY_MAIN_CP=${MY_JAR_BASE}:${MY_DEPENDENCY_CP}
else
MY_MAIN_CP=${MY_JAR_BASE}
fi
MY_FINAL_CP=conf:${MY_MAIN_CP}
MY_MAIN_CLASS_main=com.springrts.springls.Main
MY_MAIN_CLASS_accountUtils=com.springrts.springls.accounts.AccountUtils
MY_MAIN_CLASS=${MY_MAIN_CLASS_main}
MY_OPTIONAL_OPTS=""
if [ ${DBG_PORT} ]; then
MY_DEBUG_OPTS="-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${DBG_PORT} -Djava.compiler=NONE -Xnoagent"
else
MY_DEBUG_OPTS=""
fi
MY_OPTIONAL_OPTS="${MY_OPTIONAL_OPTS} ${MY_DEBUG_OPTS}"
USERS_ARGS=$@
# check if the user supplied args contain "--daemon"
# NOTE This is quite hacky, but non-bash shells freak out
# if we try to supply something like "-p 8200" to the test program
DAEMON_ARG_GIVEN=$(echo "${USERS_ARGS}" | sed -e "s/.*\\([ \t]\\|^\\)--daemon\\([ \t]\\|$\\).*/ZZZZZZZZZZZZZZZ/")
DAEMON_ARG_GIVEN=$(echo "${DAEMON_ARG_GIVEN}" | sed -e "s/.*[^Z].*//g")
# remove "--daemon", if it is present
USERS_ARGS=$(echo "${USERS_ARGS}" | sed -e "s/\\([ \t]\\|^\\)--daemon\\([ \t]\\|$\\)/ /")
if [ -z "${DAEMON_ARG_GIVEN}" ]; then
echo "Run in-shell..."
# run normal (not as daemon) if --daemon switch was not given
java -cp "${MY_FINAL_CP}" ${MY_OPTIONAL_OPTS} ${MY_MAIN_CLASS} ${USERS_ARGS}
else
echo "Run as daemon..."
nohup java -cp "${MY_FINAL_CP}" ${MY_OPTIONAL_OPTS} ${MY_MAIN_CLASS} ${USERS_ARGS} > /dev/null &
# output the PID to file ${PID_FILE}
echo $! > ${PID_FILE}
# Note: The PID file is not deleted on process end
fi