提交 | 用户 | 时间
|
722af2
|
1 |
#!/bin/sh |
X |
2 |
# ./ry.sh start 启动 stop 停止 restart 重启 status 状态 |
|
3 |
AppName=dl-admin.jar |
|
4 |
|
|
5 |
# JVM参数 |
|
6 |
JVM_OPTS="-Dname=$AppName -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC" |
|
7 |
APP_HOME=`pwd` |
|
8 |
LOG_PATH=$APP_HOME/logs/$AppName.log |
|
9 |
|
|
10 |
if [ "$1" = "" ]; |
|
11 |
then |
|
12 |
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {start|stop|restart|status} \033[0m" |
|
13 |
exit 1 |
|
14 |
fi |
|
15 |
|
|
16 |
if [ "$AppName" = "" ]; |
|
17 |
then |
|
18 |
echo -e "\033[0;31m 未输入应用名 \033[0m" |
|
19 |
exit 1 |
|
20 |
fi |
|
21 |
|
|
22 |
function start() |
|
23 |
{ |
|
24 |
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'` |
|
25 |
|
|
26 |
if [ x"$PID" != x"" ]; then |
|
27 |
echo "$AppName is running..." |
|
28 |
else |
|
29 |
nohup java $JVM_OPTS -jar $AppName > /dev/null 2>&1 & |
|
30 |
echo "Start $AppName success..." |
|
31 |
fi |
|
32 |
} |
|
33 |
|
|
34 |
function stop() |
|
35 |
{ |
|
36 |
echo "Stop $AppName" |
|
37 |
|
|
38 |
PID="" |
|
39 |
query(){ |
|
40 |
PID=`ps -ef |grep java|grep $AppName|grep -v grep|awk '{print $2}'` |
|
41 |
} |
|
42 |
|
|
43 |
query |
|
44 |
if [ x"$PID" != x"" ]; then |
|
45 |
kill -TERM $PID |
|
46 |
echo "$AppName (pid:$PID) exiting..." |
|
47 |
while [ x"$PID" != x"" ] |
|
48 |
do |
|
49 |
sleep 1 |
|
50 |
query |
|
51 |
done |
|
52 |
echo "$AppName exited." |
|
53 |
else |
|
54 |
echo "$AppName already stopped." |
|
55 |
fi |
|
56 |
} |
|
57 |
|
|
58 |
function restart() |
|
59 |
{ |
|
60 |
stop |
|
61 |
sleep 2 |
|
62 |
start |
|
63 |
} |
|
64 |
|
|
65 |
function status() |
|
66 |
{ |
|
67 |
PID=`ps -ef |grep java|grep $AppName|grep -v grep|wc -l` |
|
68 |
if [ $PID != 0 ];then |
|
69 |
echo "$AppName is running..." |
|
70 |
else |
|
71 |
echo "$AppName is not running..." |
|
72 |
fi |
|
73 |
} |
|
74 |
|
|
75 |
case $1 in |
|
76 |
start) |
|
77 |
start;; |
|
78 |
stop) |
|
79 |
stop;; |
|
80 |
restart) |
|
81 |
restart;; |
|
82 |
status) |
|
83 |
status;; |
|
84 |
*) |
|
85 |
|
|
86 |
esac |