This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.sh
163 lines (153 loc) · 3.55 KB
/
app.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
# 环境准备
DirName=$(dirname $0)
AppHome=$(realpath $DirName)
RunHome=$AppHome/var
LogFile=$RunHome/app.log
StdFile=$RunHome/std.log
PidFile=$RunHome/run.pid
Param1="${1:-help}"
Param2=$2
ScName=mzzb-server
mkdir -p $RunHome
cd $AppHome || exit
# 函数定义
test_run() {
if [[ -f $PidFile && -n $(cat $PidFile) ]]; then
PidText=$(cat $PidFile)
if [[ $(ps -p $PidText | wc -l) -eq 2 ]]; then
Running="true"
fi
fi
}
boot_run() {
echo mvn clean spring-boot:run -Dspring-boot.run.profiles=dev
nohup bash ./mvnw clean spring-boot:run -Dspring-boot.run.profiles=dev >$StdFile 2>&1 &
echo $! >$PidFile
echo "The server is starting : $!"
}
build_if() {
JarNums=$(find target -name '*.jar' -print | wc -l)
if [[ $1 == "-f" || $JarNums -eq 0 ]]; then
echo mvn clean package
bash ./mvnw clean package
fi
}
java_jar() {
JarFile=$(find target -name '*.jar' -print | tail -1)
if [[ -f $JarFile ]]; then
echo java -Xms64m -Xmx256m -jar $JarFile --spring.profiles.active=prod
nohup java -Xms64m -Xmx256m -jar $JarFile --spring.profiles.active=prod >$StdFile 2>&1 &
echo $! >$PidFile
echo "The server is starting : $!"
else
echo "Could not start, jar file not found"
fi
}
kill_app() {
if [[ $1 == "-f" ]]; then
echo kill -9 $PidText
kill -9 $PidText
sleep 1
else
echo kill $PidText
kill $PidText
while /bin/true; do
sleep 1
[[ $(ps -p $PidText | wc -l) -lt 2 ]] && break
done
fi
[[ -f $PidFile ]] && rm $PidFile
echo "The server is stopped"
}
try_stop() {
if [[ $Running == "true" ]]; then
if [[ $1 == "-f" ]]; then
kill_app
sleep 1
else
echo "The server cannot be started, it has already started : $PidText"
exit 0
fi
fi
}
test_run
# 参数解析
case $Param1 in
d | dd | dev)
try_stop -f
boot_run
sleep 1
tail -f $StdFile
;;
st | start)
build_if $Param2
try_stop $Param2
java_jar
;;
qt | stop)
if [[ $Running == "true" ]]; then
kill_app $Param2
else
echo "The server is not running"
fi
;;
rt | restart)
build_if
try_stop -f
java_jar
;;
vt | status)
if [[ $Running == "true" ]]; then
echo "The server is running : $PidText"
else
echo "The server is not running"
fi
;;
log)
if [[ $Param2 == "-a" ]]; then
less $LogFile
else
tail -f $LogFile
fi
;;
std)
if [[ $Param2 == "-a" ]]; then
less $StdFile
else
tail -f $StdFile
fi
;;
fed)
echo git fetch origin develop
git fetch origin develop
echo git reset --hard origin/develop
git reset --hard origin/develop
echo clean -fd
git clean -fd
;;
fem)
echo git fetch origin master
git fetch origin master
echo git reset --hard origin/master
git reset --hard origin/master
echo clean -fd
git clean -fd
;;
sc)
echo sudo systemctl $Param2 $ScName
sudo systemctl $Param2 $ScName
;;
*)
echo "usage: bash app.sh [d|dd|dev]"
echo "usage: bash app.sh [st|start] [-f]"
echo "usage: bash app.sh [qt|stop] [-f]"
echo "usage: bash app.sh [rt|restart]"
echo "usage: bash app.sh [vt|status]"
echo "usage: bash app.sh log [-a]"
echo "usage: bash app.sh std [-a]"
echo "usage: bash app.sh fed"
echo "usage: bash app.sh fem"
echo "usage: bash app.sh sc [start|stop|restart]"
;;
esac