-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathspring-boot.sh
executable file
·111 lines (90 loc) · 2.44 KB
/
spring-boot.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
109
110
111
#!/bin/bash
#
# Startup script for a spring boot project
#
# chkconfig: - 84 16
# description: spring boot project
# Source function library.
[ -f "/etc/rc.d/init.d/functions" ] && . /etc/rc.d/init.d/functions
[ -z "$JAVA_HOME" -a -x /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
# the name of the project, will also be used for the war file, log file, ...
PROJECT_NAME=springboot
# the user which should run the service
SERVICE_USER=root
# base directory for the spring boot jar
SPRINGBOOTAPP_HOME=/usr/local/$PROJECT_NAME
export SPRINGBOOTAPP_HOME
# the spring boot war-file
SPRINGBOOTAPP_WAR="$SPRINGBOOTAPP_HOME/$PROJECT_NAME.war"
# java executable for spring boot app, change if you have multiple jdks installed
SPRINGBOOTAPP_JAVA=$JAVA_HOME/bin/java
# spring boot log-file
LOG="/var/log/$PROJECT_NAME/$PROJECT_NAME.log"
LOCK="/var/lock/subsys/$PROJECT_NAME"
RETVAL=0
pid_of_spring_boot() {
pgrep -f "java.*$PROJECT_NAME"
}
start() {
[ -e "$LOG" ] && cnt=`wc -l "$LOG" | awk '{ print $1 }'` || cnt=1
echo -n $"Starting $PROJECT_NAME: "
cd "$SPRINGBOOTAPP_HOME"
su $SERVICE_USER -c "nohup $SPRINGBOOTAPP_JAVA -jar \"$SPRINGBOOTAPP_WAR\" >> \"$LOG\" 2>&1 &"
while { pid_of_spring_boot > /dev/null ; } &&
! { tail --lines=+$cnt "$LOG" | grep -q ' Started \S+ in' ; } ; do
sleep 1
done
pid_of_spring_boot > /dev/null
RETVAL=$?
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
echo
[ $RETVAL = 0 ] && touch "$LOCK"
}
stop() {
echo -n "Stopping $PROJECT_NAME: "
pid=`pid_of_spring_boot`
[ -n "$pid" ] && kill $pid
RETVAL=$?
cnt=10
while [ $RETVAL = 0 -a $cnt -gt 0 ] &&
{ pid_of_spring_boot > /dev/null ; } ; do
sleep 1
((cnt--))
done
[ $RETVAL = 0 ] && rm -f "$LOCK"
[ $RETVAL = 0 ] && success $"$STRING" || failure $"$STRING"
echo
}
status() {
pid=`pid_of_spring_boot`
if [ -n "$pid" ]; then
echo "$PROJECT_NAME (pid $pid) is running..."
return 0
fi
if [ -f "$LOCK" ]; then
echo $"${base} dead but subsys locked"
return 2
fi
echo "$PROJECT_NAME is stopped"
return 3
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL