forked from oikomi/FishChatServer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathr.sh
255 lines (228 loc) · 3.99 KB
/
r.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
OS=`uname|awk '{$1=tolower($1);print $1}'`
#echo "OS=$OS"
PREFIX=""
if [ $OS != "linux" ]
then
PREFIX=".exe"
fi
#echo "PREFIX=$PREFIX"
function help_clean {
echo -e "$0 clean"
echo -e " clean exe files of gateway/msg_server/manager/router/monitor/client"
}
function help_build {
echo -e "$0 build <nil>|server|gateway|msg_server|manager|router|monitor|client"
echo -e " <nil>|server: means to build all: gateway/msg_erver/manager/router/monitor/client"
}
function help_start {
echo -e "$0 start <nil>|server|redis|mongo"
echo -e " <nil>|server: means to start all: msg_erver/gateway/manager/router/monitor"
}
function help_stop {
echo -e "$0 stop <nil>|server|redis|mongo"
echo -e " <nil>|server: means to stop all: msg_erver/gateway/manager/router/monitor"
}
function Usage {
echo -e "Usage: $0 <cmd> <arg>"
echo -e "<cmd> : clean|build|start|stop"
echo -e "<arg> : <nil>|server|redis|mongo|gateway|msg_server|manager|router|monitor|client"
echo -e "Descriptions:"
help_clean
help_build
help_start
help_stop
}
function proc_help {
case $1 in
clean)
help_clean ;;
build)
help_build ;;
start)
help_start ;;
stop)
help_stop ;;
*)
Usage ;;
esac
}
function clean {
rm -f $1/$1$PREFIX
}
function proc_clean {
clean gateway
clean monitor
clean msg_server
clean router
clean manager
clean client
}
function build {
case "$1" in
gateway|msg_server|router|manager|monitor|client)
echo -e "===>building $1..."
cd $1
go build -v
cd ..
;;
esac
}
function proc_build {
case "a$1" in
agateway|amsg_server|arouter|amanager|amonitor|aclient)
build $1
;;
aserver|a)
build gateway
build msg_server
build router
build manager
build monitor
build client
;;
*)
proc_help ;;
esac
}
function start {
echo "#======================================="
read -p "start $1?[y|n]" ANS
case $ANS in
n|N|no|NO|No) exit 0 ;;
y|Y|yes|Yes) ;;
*) ;;
esac
case "x$1" in
"xmanager"|"xmonitor"|"xrouter"|"xgateway")
./$1/$1$PREFIX -conf_file=./$1/$1.json &
;;
"xmsg_server")
./$1/$1$PREFIX -conf_file=./$1/$1.19001.json &
./$1/$1$PREFIX -conf_file=./$1/$1.19000.json &
;;
"xredis")
if [ $OS == "linux" ]
then
sudo /etc/init.d/redis_6379 start
else
net start redis
fi
;;
"xmongo")
if [ $OS == "linux" ]
then
$DIR=$HOME/RDAWatchServer
if [ ! -d $DIR/db ]; then
mkdir $DIR/db
fi
mongod --dbpath=$DIR/db --storageEngine=mmapv1 --logpath=$DIR/mongod.log --logappend --fork &
else
net start mongodb
fi
;;
esac
}
function proc_start {
case "x$1" in
"x"|"xserver")
start msg_server
start gateway
start router
start manager
start monitor
;;
"xredis"|"xmongo")
start $1
;;
*)
proc_help ;;
esac
}
function stop {
pids=`ps -ef | grep $1 | awk '{print $2}'`
for item in ${pids[*]}; do
echo "kill $1:$item"
kill -9 $item
done
}
function proc_stop {
case "x$1" in
"x"|"xserver")
stop monitor
stop manager
stop router
stop gateway
stop msg_server
;;
"xmanager"|"xmonitor"|"xrouter"|"xgateway"|"xmsg_server")
stop $1
;;
"xredis")
if [ $OS == "linux" ]
then
sudo /etc/init.d/redis_6379 stop
else
net stop redis
fi
;;
"xmongo")
if [ $OS == "linux" ]
then
stop mongod
else
net stop mongodb
fi
;;
*)
proc_help ;;
esac
}
function status {
pids=`ps -ef | grep $1 | awk '{print $2}'`
for item in ${pids[*]}; do
echo "$1:$item"
done
}
function proc_status {
case "x$1" in
"x"|"xserver")
status monitor
status manager
status router
status gateway
status msg_server
;;
"xmanager"|"xmonitor"|"xrouter"|"xgateway"|"xmsg_server")
status $1
;;
"xredis")
#if [ $OS == "linux" ]
#then
#else
#fi
;;
"xmongo")
#if [ $OS == "linux" ]
#then
#else
#fi
;;
esac
}
case "$1" in
clean)
proc_clean $2 ;;
build)
proc_build $2 ;;
start)
proc_start $2 ;;
stop)
proc_stop $2 ;;
status)
proc_status $2 ;;
help)
proc_help $2 ;;
*)
proc_help;;
esac