This repository has been archived by the owner on Jul 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ez
173 lines (154 loc) · 3.78 KB
/
ez
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
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
log_path=./logs
start(){
app_code=$1
start_app=''
if [ $app_code = 'all' ] ; then
start_app="\-Dez.flag=ez_sh"
else
start_app="\-Dez.flag=ez_sh -jar ./app/$app_code/$app_code.jar"
fi
if [ `(ps -ef |grep "$start_app" ) | grep -v grep | wc -l ` -eq 0 ] ; then
if [ `(ps -ef |grep "\-Dez.flag=ez_sh -jar ./app/gateway/gateway.jar" ) | grep -v grep | wc -l ` -eq 0 ] ; then
echo "Starting gateway"
mkdir -p $log_path/gateway/
nohup java -Dez.flag=ez_sh -jar ./app/gateway/gateway.jar > $log_path/gateway/out.log &
sleep 10s
echo "Started gateway"
fi
files=`ls ./app/`
for file in $files
do
app=`echo $file|cut -d "." -f1`
if [ $app != 'gateway' ] ; then
if [ $1 = 'all' ] || [ "$1" = $app ]; then
mkdir -p $log_path/$app/
nohup java -Dez.flag=ez_sh -jar ./app/$app/$app.jar > $log_path/$app/out.log &
echo "Started $app"
fi
fi
done
else
echo "Start $app_code fail,App Not Stopped."
fi
if [ $app_code != 'all' ] ; then
tailf $app_code
fi
}
stop(){
app_code=$1
stop_app=''
if [ $app_code = 'all' ] ; then
stop_app="\-Dez.flag=ez_sh"
else
stop_app="\-Dez.flag=ez_sh -jar ./app/$app_code/$app_code.jar"
fi
pid=`(ps -ef |grep "$stop_app" ) | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ] ; then
echo "Stop... $app_code"
kill $pid
fi
count=0
while(true)
do
if [ `(ps -ef |grep "$stop_app" ) | grep -v grep | wc -l ` -eq 0 ] ; then
echo "Stopped $app_code"
break
fi
if [ $count -eq 50 ] ; then # = 50 sec
echo "Stop $app_code fail,use kill -9"
kill -9 `(ps -ef |grep "$stop_app" ) | grep -v grep | awk '{print $2}'`
fi
sleep 1
let count++
if [ $count -gt 100 ] ; then # > 100 sec
echo "Stop $app_code fail,exit."
break
fi
done
}
restart(){
app_code=$1
stop $app_code
start $app_code
}
tailf(){
app_code=$1
exec tailf -n 500 $log_path/$app_code/out.log
}
trace(){
inst_code=$1
cat $log_path/*/out.log | grep "=|$instCode|" | sort -k 3 -t \|
}
deploy(){
app_code=$1
stop $app_code
if [ -d app/$app_code/ ] ; then
echo "backup $app_code"
mkdir -p backup/$app_code/
tar -czf backup/$app_code/`date +%Y%m%d%H%M%S`.tar.gz -C app/$app_code ./
echo "delete $app_code"
rm -rf app/$app_code/
fi
mkdir -p app/$app_code/config/
cp -r prepare/$app_code/* app/$app_code/
cp -r config/$app_code/* app/$app_code/config/
rm -rf prepare/$app_code/*
start $app_code
}
show(){
ps -ef | grep "\-Dez.flag=ez_sh" | grep -v grep
}
tip(){
echo "============== [ EZ-Framework ] Deploy Script =============="
echo ">> start <app code | all >"
echo ">> stop <app code | all >"
echo ">> restart <app code | all >"
echo ">> tailf <app code>"
echo ">> trace <instance code>"
echo "=============="
echo ">> deploy <app code>"
echo ">> show"
echo "======================================================="
exit 1;
}
# ============== load ==============
. /etc/profile
if [ $# -eq 0 ] ; then
tip
fi
command=$1
args=$2
case $command in
"start")
if [ "$args" = "" ] ; then
tip
fi
start $args ;;
"stop")
if [ "$args" = "" ] ; then
tip
fi
stop $args ;;
"restart")
if [ "$args" = "" ] ; then
tip
fi
restart $args ;;
"tailf")
if [ "$args" = "" ] ; then
tip
fi
tailf $args ;;
"trace")
trace $args ;;
"deploy")
if [ "$args" = "" ] ; then
tip
fi
deploy $args ;;
"show")
show ;;
* )
tip
esac