-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.sh
67 lines (52 loc) · 1.72 KB
/
reset.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
#!/bin/bash
export SERVER_PORT=8555
export CONSOLE_PORT=7555
# 退出已经启动的服务器
# 通过服务器监听的端口来找到对应的服务器进程,然后退出
servers=`netstat -ntlp | grep $CONSOLE_PORT | sort | awk '{print $NF}' |awk -F'/' '{print $1}'`
for i in $servers
do
echo $i server is running, stop it now
skill -9 $i
done
echo start server ...
logFileName="log_0.txt"
if [ -f "$logFileName" ]; then
logFileMax=`for i in $(ls | grep "log_.*.txt" | grep -o "[0-9]\+");do echo $i;done|sort -nr|head -1`
if [ $logFileMax -gt 4 ] ; then
rm log_1.txt
for ((i=2; i<=$logFileMax; i++))
do
logBakFileName1="log_$(($i)).txt"
logBakFileName2="log_$(($i-1)).txt"
mv $logBakFileName1 $logBakFileName2
done
logBakFileName="log_$(($logFileMax)).txt"
else
logBakFileName="log_$(($logFileMax+1)).txt"
fi
echo "backup log files: mv" $logFileName "to" $logBakFileName
mv $logFileName $logBakFileName
fi
# ./skynet/skynet config.lua
./skynet/skynet config.lua &
sleep 0.1
cat $logFileName
servers=`netstat -ntlp | grep $SERVER_PORT | sort | awk '{print $NF}' |awk -F'/' '{print $1}'`
isStarted=false
for i in $servers
do
isStarted=true
echo "====================================================="
echo $i server started sucessfull
echo log file is $logFileName
echo listen on port $SERVER_PORT
echo "====================================================="
tail -f -n 0 $logFileName
done
if ! $isStarted; then
echo "====================================================="
echo server started failed!!!
echo log file is $logFileName
echo "====================================================="
fi