-
Notifications
You must be signed in to change notification settings - Fork 102
/
blog.sh
93 lines (86 loc) · 1.64 KB
/
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
93
#!/bin/bash
# jar文件名
FILE_NAME=blog.jar
# log文件夹
LOG_DIR=$(pwd)/logs
# 获得进程id
get_pid(){
pid=`ps -ef|grep $FILE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
echo "$pid"
}
# 运行jar包
start_up(){
pid=$(get_pid)
if [ "$pid" ]
then
echo "Blog already startup!"
else
nohup java -jar ./$FILE_NAME --spring.profiles.active=prod > /dev/null 2>&1 &
fi
}
# 停止进程
shut_down(){
pid=$(get_pid)
if [ "$pid" ]
then
kill -9 $pid
echo "Stop success!"
else
echo "Blog is not running!"
fi
}
# 查看日志
show_log(){
# 判断是否有logs文件夹,没有则创建,用于存储日志
if [ ! -d "${LOG_DIR}" ]; then
mkdir $LOG_DIR
# 同时创建日志文件
touch $LOG_DIR/blog.log
fi
tail -f $LOG_DIR/blog.log
}
# 显示帮助
show_help(){
echo -e "Usage: sh blog.sh start|stop|restart|status|log"
exit
}
show_status(){
pid=$(get_pid)
if [ "$pid" ]
then
echo "Blog is running with pid: $pid"
else
echo "Blog is not running!"
fi
}
if [ ! -n "$1" ] ;then
show_help
else
case "$1" in
"start")
start_up
sleep 1
show_log
;;
"stop")
shut_down
;;
"restart")
shut_down
sleep 1
start_up
sleep 1
show_log
;;
"status")
show_status
;;
"log")
show_log
;;
*)
echo 'Invalid command!'
show_help
;;
esac
fi