-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.sh
98 lines (89 loc) · 2.19 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
#!/bin/bash
option=$1 #参数
appName=${2} #应用名称
appName=${appName:=main}
#编译开发应用
buildDevApp(){
if read -p "please enter version:" version
then
if [ ! -z $version ]
then
go build -ldflags "-X main._version_=$version" -o ${appName}
echo "Dev programe is success"
echo "App name is 【${appName}】"
echo "Version is 【$version】"
else
echo "version is none"
fi
else
echo "sorry. too slow!"
fi
}
#编译生产应用
buildProdApp(){
if read -p "please enter version:" version
then
if [ ! -z $version ]
then
go build -ldflags "-X main._version_=${version}" -tags=prod -o ${appName}
echo "Prod programe is success"
echo "App name is 【${appName}】"
echo "Version is 【$version】"
else
echo "version is none"
fi
else
echo "sorry. too slow!"
fi
}
#后台运行应用
nohupApp(){
nohup ./${appName} &
}
#查看应用运行状态
showStatus(){
tail -f nohup.out
}
#平滑重启应用
restartApp(){
ps aux | grep "${appName}" | grep -v grep | awk '{print $2}' | xargs -i kill -1 {}
}
#关闭应用
stopApp(){
ps aux | grep "${appName}" | grep -v grep | awk '{print $2}' | xargs -i kill -9 {}
}
#帮助
help(){
echo "Usage:"
echo ""
echo " ./app command [arguments]"
echo ""
echo "The commands are:"
echo ""
echo " dev [appName]"
echo " prod [appName]"
echo " start [appName]"
echo " restart [appName]"
echo " stop [appName]"
echo " status [appName]"
echo " -h [appName]"
}
case ${option} in
"dev")buildDevApp
;;
"prod")buildProdApp
;;
"start") nohupApp ; showStatus
;;
"restart")restartApp
;;
"stop")stopApp
;;
"status")showStatus
;;
"-h")help
;;
*)help
exit 1 #退出
;;
esac