-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
144 lines (130 loc) · 4.65 KB
/
start.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/sh
daemon=true
appname=logserver
#filebeat=filebeat.log,filebeat2.log
logfile=/var/log/logserver/all.logs
jarfile=target/$appname.jar
pwdfile=./my.pwd
[ ! -e "$jarfile" ] && jarfile=$appname.jar
[ -e $pwdfile ] && source $pwdfile
Survivor=1 Old=16 NewSize=$[Survivor*10] Xmx=$[NewSize+Old] #NewSize=Survivor*(1+1+8) Xmx=NewSize+Old
JVM_OPS="-Xmx${Xmx}m -Xms${Xmx}m -XX:NewSize=${NewSize}m -XX:MaxNewSize=${NewSize}m -XX:SurvivorRatio=8 -Xss228k"
#JVM_OPS="$JVM_OPS -Dredis -Dredis.host=localhost -Dredis.port=6379 -Dredis.pubsub=true -Dredis.pushpop=true -Dredis.queueSize=10240"
JVM_OPS="$JVM_OPS -Djava.compiler=none -Dlajax.token=${token:-xlongwei} -DcontextName=$appname -DlogLength=2048 -Dlogback.configurationFile=classpath:logback.xml"
ENV_OPS="$ENV_OPS accessKeyId=${accessKeyId:-} secret=${secret:-}"
ENV_OPS="$ENV_OPS regionId=cn-hangzhou domainName=xlongwei.com recordId=4012091293697024"
JVM_OPS="$JVM_OPS -Dfiles=false -Dlogger=logserver@log -Dmask=passw(3,15);token(3,15)"
#JVM_OPS="$JVM_OPS -Dfiles=true -Dlogger=logserver@log,apidoc@https://api.xlongwei.com/apidoc/demo/log.htm,bpmdemo@https://bpm.xlongwei.com/demo/demo/log,cms@https://cms.xlongwei.com/demo/log.json,light4j@https://api.xlongwei.com/demo/log,search@https://log.xlongwei.com/service/logserver/log"
#JVM_OPS="$JVM_OPS -Dlogger=logserver@log,apidoc@http://localhost:8081/apidoc/demo/log.htm,bpmdemo@http://localhost:8080/demo/demo/log,cms@http://localhost:8081/demo/log.json,light4j@http://localhost:8080/demo/log,search@http://localhost:9200/service/logserver/log"
#JVM_OPS="$JVM_OPS -Dlight-search=http://localhost:9200 -DuseIndexer=true -DuseSearch=true"
#JVM_OPS="$JVM_OPS -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"
ENV_OPS="$ENV_OPS workerThreads=1 ioThreads=1 enableHttps=false"
#ENV_OPS="$ENV_OPS PATH=/usr/java/jdk1.8.0_161/bin:$PATH"
usage(){
echo "Usage: start.sh ( commands ... )"
echo "commands: "
echo " status check the running status"
echo " start start $appname"
echo " stop stop $appname"
echo " restart stop && start"
echo " clean clean target"
echo " jar build $jarfile"
echo " jars copy dependencies to target"
echo " package build logser.jar and copy dependencies to target"
echo " rebuild stop && build && start"
echo " refresh stop && clean && build && jars && start"
echo " deploy package all to one-fat $jarfile"
echo " redeploy package all to one-fat $jarfile and restart"
}
status(){
PIDS=`ps -ef | grep java | grep "$jarfile" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "$appname is not running!"
else
for PID in $PIDS ; do
echo "$appname has pid: $PID!"
done
fi
}
stop(){
PIDS=`ps -ef | grep java | grep "$jarfile" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "$appname is not running!"
else
echo -e "Stopping $appname ..."
for PID in $PIDS ; do
echo -e "kill $PID"
kill $PID > /dev/null 2>&1
done
fi
}
wait(){
PIDS=`ps -ef | grep java | grep "$jarfile" |awk '{print $2}'`
if [ ! -z "$PIDS" ]; then
COUNT=0 WAIT=9
while [ $COUNT -lt $WAIT ]; do
echo -e ".\c"
sleep 1
PIDS=`ps -ef | grep java | grep "$jarfile" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
break
fi
let COUNT=COUNT+1
done
PIDS=`ps -ef | grep java | grep "$jarfile" |awk '{print $2}'`
if [ ! -z "$PIDS" ]; then
for PID in $PIDS ; do
echo -e "kill -9 $PID"
kill -9 $PID > /dev/null 2>&1
done
fi
fi
}
clean(){
mvn clean
}
jar(){
mvn compile jar:jar
}
dependency(){
mvn dependency:copy-dependencies -DoutputDirectory=target
}
deploy(){
mvn package -Prelease -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
}
start(){
echo "starting $appname ..."
JVM_OPS="-server -Djava.awt.headless=true $JVM_OPS"
if [ "$daemon" = "true" ]; then
if [ -z "$filebeat" ]; then
env $ENV_OPS setsid java $JVM_OPS -Dlogfile=$logfile -jar $jarfile >> /dev/null 2>&1 &
else
env $ENV_OPS setsid java $JVM_OPS -Dlogfile=$logfile -Dfilebeat=$filebeat -cp $jarfile com.xlongwei.logserver.FileBeat >> /dev/null 2>&1 &
fi
else
if [ -z "$filebeat" ]; then
env $ENV_OPS java $JVM_OPS -jar $jarfile 2>&1
else
env $ENV_OPS java $JVM_OPS -Dfilebeat=$filebeat -cp $jarfile com.xlongwei.logserver.FileBeat 2>&1
fi
fi
}
if [ $# -eq 0 ]; then
usage
else
case $1 in
status) status ;;
start) start ;;
stop) stop ;;
restart) stop && wait && start ;;
clean) clean ;;
jar) jar ;;
jars) dependency ;;
package) jar && dependency ;;
rebuild) stop && jar && start ;;
refresh) stop && clean && jar && dependency && start ;;
deploy) deploy ;;
redeploy) stop && deploy && start ;;
*) usage ;;
esac
fi