-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.sh
62 lines (54 loc) · 1.29 KB
/
run.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
#!/bin/bash
wk='/root/go/src/weixinsdk'
m_BuildingName=weixinsdk
# 进程pid
#命令帮助
shell_usage(){
echo "Usage: $0 (restart|dev|build)"
}
do_restart(){
process=$(ps -ef | grep $m_BuildingName | grep -v grep | awk '{print $2}')
if [ "$process" != "" ];then
echo $(kill -TERM $process)
echo $(nohup ./$m_BuildingName > $m_BuildingName.log 2>&1 &)
fi
}
#开发环境 ./run.sh dev
do_dev(){
process=$(ps -ef | grep $m_BuildingName | grep -v grep | awk '{print $2}')
if [ "$process" != "" ];then
echo $(kill -TERM $process)
fi
cd ${wk}/src &&go build -o $wk/$m_BuildingName .
cd ${wk} && chmod +x $m_BuildingName && ./$m_BuildingName
}
#正式环境
do_build(){
process=$(ps -ef | grep $m_BuildingName | grep -v grep | awk '{print $2}')
if [ "$process" != "" ];then
echo $(kill -TERM $process)
fi
cd ${wk}/src &&go build -o $wk/$m_BuildingName .
cd ${wk} && chmod +x $m_BuildingName
echo $(nohup ./$m_BuildingName > $m_BuildingName.log 2>&1 &)
}
#启动函数
main(){
#switch切换函数
case $1 in
dev)
do_dev
;;
build)
do_build
;;
restart)
do_restart
;;
*)
shell_usage;
exit 1
esac
}
#执行函数
main $1 $2