-
Notifications
You must be signed in to change notification settings - Fork 160
/
app.sh
executable file
·108 lines (89 loc) · 1.75 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
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
## Author LinkinStar
## UPDATE 2019-01-05
version="1.0.1";
appName=$2
if [ -z $appName ];then
appName=`ls -t |grep .jar$ |head -n1`
fi
function start()
{
count=`ps -ef |grep java|grep $appName|wc -l`
if [ $count != 0 ];then
echo "Maybe $appName is running, please check it..."
else
echo "The $appName is starting..."
nohup java -jar ./$appName -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -Xms512M -Xmx4G > /dev/null 2>&1 &
fi
}
function stop()
{
appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
if [ -z $appId ];then
echo "Maybe $appName not running, please check it..."
else
echo "The $appName is stopping..."
kill $appId
fi
}
function restart()
{
# get release version
releaseApp=`ls -t |grep .jar$ |head -n1`
# get last version
lastVersionApp=`ls -t |grep .jar$ |head -n2 |tail -n1`
appName=$lastVersionApp
stop
for i in {5..1}
do
echo -n "$i "
sleep 1
done
echo 0
backup
appName=$releaseApp
start
}
function backup()
{
# get backup version
backupApp=`ls |grep -wv $releaseApp$ |grep .jar$`
# create backup dir
if [ ! -d "backup" ];then
mkdir backup
fi
# backup
for i in ${backupApp[@]}
do
echo "backup" $i
mv $i backup
done
}
function status()
{
appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`
if [ -z $appId ]
then
echo -e "\033[31m Not running \033[0m"
else
echo -e "\033[32m Running [$appId] \033[0m"
fi
}
function usage()
{
echo "Usage: $0 {start|stop|restart|status|stop -f}"
echo "Example: $0 start"
exit 1
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
usage;;
esac