Skip to content

Commit 3458b94

Browse files
committed
Merge pull request #3243 from joshiste/init-improvements
* init-improvements: Update executable jar documentation Improve executable jar launch script
2 parents a0dde9f + c417e90 commit 3458b94

File tree

2 files changed

+46
-23
lines changed
  • spring-boot-docs/src/main/asciidoc
  • spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools

2 files changed

+46
-23
lines changed

spring-boot-docs/src/main/asciidoc/deployment.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ the default behavior in a script or on the command line:
445445
in the script.
446446
|===
447447

448+
TIP: With the exception of `JARFILE` and `APP_NAME`, the above settings can be placed in
449+
a `.conf` next to the jar. For example the jar `/var/myapp/myapp.jar` would attempt to
450+
source the configuration file `/var/myapp/myapp.conf`.
451+
448452

449453

450454
[[deployment-whats-next]]

spring-boot-tools/spring-boot-loader-tools/src/main/resources/org/springframework/boot/loader/tools/launch.script

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,40 @@
99
# :: Spring Boot Startup Script ::
1010
#
1111

12+
### BEGIN INIT INFO
13+
# Provides: spring-boot-application
14+
# Required-Start: $remote_fs $syslog $network
15+
# Required-Stop: $remote_fs $syslog $network
16+
# Default-Start: 2 3 4 5
17+
# Default-Stop: 0 1 6
18+
# Short-Description: Spring Boot Application
19+
# Description: Spring Boot Application
20+
### END INIT INFO
21+
1222
[[ -n "$DEBUG" ]] && set -x
1323

24+
# Initialize variables that cannot be provided by a .conf file
1425
WORKING_DIR="$(pwd)"
1526
[[ -n "$JARFILE" ]] && jarfile="$JARFILE"
1627
[[ -n "$APP_NAME" ]] && identity="$APP_NAME"
28+
29+
# Follow symlinks to find the real jar and detect init.d script
30+
cd $(dirname "$0")
31+
[[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0")
32+
while [[ -L "$jarfile" ]]; do
33+
[[ "$jarfile" =~ "init.d" ]] && init_script=$(basename "$jarfile")
34+
jarfile=$(readlink "$jarfile")
35+
cd $(dirname "$jarfile")
36+
jarfile=$(pwd)/$(basename "$jarfile")
37+
done
38+
jarfolder=$(dirname "$jarfile")
39+
cd "$WORKING_DIR"
40+
41+
# Source any config file
42+
configfile=$(basename "${jarfile%.*}.conf")
43+
[[ -r ${jarfolder}/${configfile} ]] && source ${jarfolder}/${configfile}
44+
45+
# Initialize PID/LOG locations if they weren't provided by the config file
1746
[[ -z "$PID_FOLDER" ]] && PID_FOLDER="/var/run"
1847
[[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="/var/log"
1948
! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp"
@@ -22,6 +51,18 @@ WORKING_DIR="$(pwd)"
2251
# Setup defaults
2352
[[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run"
2453

54+
# Create an identity for log/pid files
55+
if [[ -z "$identity" ]]; then
56+
if [[ -n "$init_script" ]]; then
57+
identity="${init_script}"
58+
else
59+
identity=$(basename "${jarfile%.*}")_${jar_folder//\//}
60+
fi
61+
fi
62+
63+
64+
65+
2566
# ANSI Colors
2667
echoRed() { echo $'\e[0;31m'$1$'\e[0m'; }
2768
echoGreen() { echo $'\e[0;32m'$1$'\e[0m'; }
@@ -37,34 +78,13 @@ isRunning() {
3778
ps -p $1 &> /dev/null
3879
}
3980

40-
# Follow symlinks to find the real jar and detect init.d script
41-
cd $(dirname "$0")
42-
[[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0")
43-
while [[ -L "$jarfile" ]]; do
44-
[[ "$jarfile" =~ "init.d" ]] && init_script=$(basename "$jarfile")
45-
jarfile=$(readlink "$jarfile")
46-
cd $(dirname "$jarfile")
47-
jarfile=$(pwd)/$(basename "$jarfile")
48-
done
49-
cd "$WORKING_DIR"
50-
5181
# Determine the script mode
5282
action="run"
5383
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
5484
action="$1"
5585
shift
5686
fi
5787

58-
# Create an identity for log/pid files
59-
if [[ -z "$identity" ]]; then
60-
if [[ -n "$init_script" ]]; then
61-
identity="${init_script}"
62-
else
63-
jar_folder=$(dirname "$jarfile")
64-
identity=$(basename "${jarfile%.*}")_${jar_folder//\//}
65-
fi
66-
fi
67-
6888
# Build the pid and log filenames
6989
if [[ "$identity" == "$init_script" ]] || [[ "$identity" == "$APP_NAME" ]]; then
7090
PID_FOLDER="$PID_FOLDER/${identity}"
@@ -88,7 +108,7 @@ else
88108
fi
89109

90110
# Build actual command to execute
91-
command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $jarfile $@"
111+
command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS $jarfile $RUN_ARGS $@"
92112

93113
# Action functions
94114
start() {
@@ -166,4 +186,3 @@ run)
166186
esac
167187

168188
exit 0
169-

0 commit comments

Comments
 (0)