-
Notifications
You must be signed in to change notification settings - Fork 750
/
control
140 lines (126 loc) · 2.91 KB
/
control
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
#!/bin/bash
WORKSPACE=$(cd $(dirname $0)/; pwd)
cd $WORKSPACE
mkdir -p log conf
module=
appname=$(basename $WORKSPACE)
## 注意:这里每个应用的启动命令是不一样的,
## 启动命令必须在前端运行(即不需要nohup)运行,
## 系统会自动加上nohup运行
## 例如:run_cmd=java -jar spring-hello.jar
run_cmd="./fileserver server"
conf=conf/cfg.json
pidfile=conf/app.pid
logfile=log/app.log
function check_pid() {
if [ -f $pidfile ];then
pid=`cat $pidfile`
if [ -n $pid ]; then
running=`ps -p $pid|grep -v "PID TTY" |wc -l`
return $running
fi
fi
return 0
}
#应用发布接口
function deploy() {
#自定义发布
#例如修改配置,移动文件夹等。。。
echo "请修改deploy接口,以满足你的发布需求。"
}
#应用启动接口
function start() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$appname now is running already, pid="
cat $pidfile
return 1
fi
nohup $run_cmd &> $logfile &
echo $! > $pidfile
#echo "$appname started..., pid=$!"
sleep 3
status
}
#停止应用接口
function stop() {
pid=`cat $pidfile`
kill $pid
echo "$appname stoped..."
}
function restart() {
stop
sleep 1
start
}
#应用状态检测接口
function status() {
check_pid
running=$?
if [ $running -gt 0 ];then
echo -n "$appname now is running, pid="
cat $pidfile
#注意:以下输出不能修改,程序会自动根据这个输出做状态判断
echo "app_status:running"
else
#注意:以下输出不能修改,程序会自动根据这个输出做状态判断
echo "$appname is stoped"
echo "app_status:stoped"
fi
}
function tailf() {
timeout 50 tail -f $logfile
}
#应用构建接口
function build() {
# 注意:如果需要定制编译命令,可以修改这里
git log -1 --pretty=%h > gitversion
if [[ -f ./build.sh ]];then
sh ./build.sh #custom
elif [[ -f ./pom.xml ]];then
mvn install #java
elif [[ -f ./package.json ]];then
npm install #node
npm run product
fi
if [ $? -ne 0 ]; then
exit $?
fi
}
function pack() {
build
version=`cat gitversion`
file_list="control $appname"
tar zcf $appname-$version.tar.gz gitversion $file_list
}
function packbin() {
build
git log -1 --pretty=%h > gitversion
version=`cat gitversion`
tar zcvf $appname-bin-$version.tar.gz $appname gitversion
}
function help() {
echo "$0 start|stop|restart|status|tail|build|pack|deploy|help"
}
if [ "$1" == "" ]; then
help
elif [ "$1" == "stop" ];then
stop
elif [ "$1" == "start" ];then
start
elif [ "$1" == "build" ];then
build
elif [ "$1" == "deploy" ];then
deploy
elif [ "$1" == "restart" ];then
restart
elif [ "$1" == "pack" ];then
pack
elif [ "$1" == "status" ];then
status
elif [ "$1" == "tail" ];then
tailf
else
help
fi