forked from ZHENFENG13/spring-boot-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my-blog.sh
92 lines (82 loc) · 1.59 KB
/
my-blog.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
#!/bin/bash
# author: 13
# date: 2017-06-30
env_args="-Xms128m -Xmx128m"
sleeptime=0
arglen=$#
# get my-blog pid
get_pid(){
pname="`find .. -name 'my-blog*.jar'`"
pname=${pname:3}
pid=`ps -ef | grep $pname | grep -v grep | awk '{print $2}'`
echo "$pid"
}
startup(){
#构建并启动
mvn clean install -Dmaven.test.skip=true
pid=$(get_pid)
if [ "$pid" != "" ]
then
echo "Blog already startup!"
else
jar_path=`find .. -name 'my-blog*.jar'`
echo "jarfile=$jar_path"
cmd="java $1 -jar $jar_path > ./my-blog.out < /dev/null &"
echo "cmd: $cmd"
java $1 -jar $jar_path > ./my-blog.out < /dev/null &
show_log
fi
}
shut_down(){
pid=$(get_pid)
if [ "$pid" != "" ]
then
kill -9 $pid
echo "Blog is stop!"
else
echo "Blog already stop!"
fi
}
show_log(){
tail -f my-blog.out
}
show_help(){
echo -e "\r\n\t欢迎使用Blog"
echo -e "\r\nUsage: sh my-blog.sh start|stop|reload|status|log"
exit
}
show_status(){
pid=$(get_pid)
if [ "$pid" != "" ]
then
echo "Blog is running with pid: $pid"
else
echo "Blog is stop!"
fi
}
if [ $arglen -eq 0 ]
then
show_help
else
if [ "$2" != "" ]
then
env_args="$2"
fi
case "$1" in
"start")
startup "$env_args"
;;
"stop")
shut_down
;;
"reload")
echo "reload"
;;
"status")
show_status
;;
"log")
show_log
;;
esac
fi