-
Notifications
You must be signed in to change notification settings - Fork 22
/
runServer.sh
executable file
·100 lines (95 loc) · 1.88 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
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/sh
ulimit -SHn 51200
dir=`dirname $0`
pidfile=server_pid
cd $dir
CP=.:config/
for file in lib/*;
do CP=${CP}:$file;
done
retval=0
# start the server
start(){
printf 'Starting the server of Migration-tool\n'
if [ -f "$pidfile" ] ; then
pid=`cat "$pidfile"`
printf 'Existing process: %d\n' "$pid"
retval=1
else
java -Xms300M \
-Xmx300M \
-XX:+UseParallelGC \
-XX:+AggressiveOpts \
-XX:+UseFastAccessorMethods \
-XX:+HeapDumpOnOutOfMemoryError \
-verbose:gc \
-XX:+PrintGCDetails \
-XX:+PrintGCTimeStamps \
-Xloggc:logs/server_gc`date +%Y%m%d%H%M%S`.log \
-cp $CP com.shata.migration.server.StartServer >>logs/server_log.log &
echo $! >"$pidfile"
if [ "$?" -eq 0 ] ; then
printf 'Done\n'
else
printf 'The server could not started\n'
retval=1
fi
fi
}
# stop the server
stop(){
printf 'Stopping the server of Migration-tool\n'
if [ -f "$pidfile" ] ; then
pid=`cat "$pidfile"`
printf "Sending the terminal signal to the process: %s\n" "$pid"
PROCESSPID=`ps -ef|awk '{print $2}'|grep "$pid"`
if [[ $PROCESSPID -ne "$pidfile" ]] ; then
rm -f "$pidfile";
printf 'Done\n'
fi
kill -TERM "$pid"
c=0
while true ; do
sleep 0.1
PROCESSPID=`ps -ef|awk '{print $2}'|grep "$pid"`
if [[ $PROCESSPID -eq "$pidfile" ]] ; then
c=`expr $c + 1`
if [ "$c" -ge 100 ] ; then
printf 'Hanging process: %d\n' "$pid"
retval=1
break
fi
else
printf 'Done\n'
rm -f "$pidfile";
break
fi
done
else
printf 'No process found\n'
retval=1
fi
}
# dispatch the command
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
hup)
hup
;;
*)
printf 'Usage: %s {start|stop|restart}\n'
exit 1
;;
esac
# exit
exit "$retval"
# END OF FILE