Improve executable jar launch script
Update the launch script used in fully executable jars to: - Include LSB-Header comments - Source `.conf` files either next to the jar for additional script configuration Fixes gh-3243
This commit is contained in:
		
							parent
							
								
									a0dde9f17d
								
							
						
					
					
						commit
						f0bb60bf9d
					
				| 
						 | 
					@ -9,11 +9,40 @@
 | 
				
			||||||
#   :: Spring Boot Startup Script ::
 | 
					#   :: Spring Boot Startup Script ::
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### BEGIN INIT INFO
 | 
				
			||||||
 | 
					# Provides:          spring-boot-application
 | 
				
			||||||
 | 
					# Required-Start:    $remote_fs $syslog $network
 | 
				
			||||||
 | 
					# Required-Stop:     $remote_fs $syslog $network
 | 
				
			||||||
 | 
					# Default-Start:     2 3 4 5
 | 
				
			||||||
 | 
					# Default-Stop:      0 1 6
 | 
				
			||||||
 | 
					# Short-Description: Spring Boot Application
 | 
				
			||||||
 | 
					# Description:       Spring Boot Application
 | 
				
			||||||
 | 
					### END INIT INFO
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[ -n "$DEBUG" ]] && set -x
 | 
					[[ -n "$DEBUG" ]] && set -x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Initialize variables that cannot be provided by a .conf file
 | 
				
			||||||
WORKING_DIR="$(pwd)"
 | 
					WORKING_DIR="$(pwd)"
 | 
				
			||||||
[[ -n "$JARFILE" ]] && jarfile="$JARFILE"
 | 
					[[ -n "$JARFILE" ]] && jarfile="$JARFILE"
 | 
				
			||||||
[[ -n "$APP_NAME" ]] && identity="$APP_NAME"
 | 
					[[ -n "$APP_NAME" ]] && identity="$APP_NAME"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Follow symlinks to find the real jar and detect init.d script
 | 
				
			||||||
 | 
					cd $(dirname "$0")
 | 
				
			||||||
 | 
					[[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0")
 | 
				
			||||||
 | 
					while [[ -L "$jarfile" ]]; do
 | 
				
			||||||
 | 
					  [[ "$jarfile" =~ "init.d" ]] && init_script=$(basename "$jarfile")
 | 
				
			||||||
 | 
					  jarfile=$(readlink "$jarfile")
 | 
				
			||||||
 | 
					  cd $(dirname "$jarfile")
 | 
				
			||||||
 | 
					  jarfile=$(pwd)/$(basename "$jarfile")
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					jarfolder=$(dirname "$jarfile")
 | 
				
			||||||
 | 
					cd "$WORKING_DIR"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Source any config file
 | 
				
			||||||
 | 
					configfile=$(basename "${jarfile%.*}.conf")
 | 
				
			||||||
 | 
					[[ -r ${jarfolder}/${configfile} ]] && source ${jarfolder}/${configfile}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Initialize PID/LOG locations if they weren't provided by the config file
 | 
				
			||||||
[[ -z "$PID_FOLDER" ]] && PID_FOLDER="/var/run"
 | 
					[[ -z "$PID_FOLDER" ]] && PID_FOLDER="/var/run"
 | 
				
			||||||
[[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="/var/log"
 | 
					[[ -z "$LOG_FOLDER" ]] && LOG_FOLDER="/var/log"
 | 
				
			||||||
! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp"
 | 
					! [[ -x "$PID_FOLDER" ]] && PID_FOLDER="/tmp"
 | 
				
			||||||
| 
						 | 
					@ -22,6 +51,18 @@ WORKING_DIR="$(pwd)"
 | 
				
			||||||
# Setup defaults
 | 
					# Setup defaults
 | 
				
			||||||
[[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run"
 | 
					[[ -z "$MODE" ]] && MODE="{{mode:auto}}" # modes are "auto", "service" or "run"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Create an identity for log/pid files
 | 
				
			||||||
 | 
					if [[ -z "$identity" ]]; then
 | 
				
			||||||
 | 
					  if [[ -n "$init_script" ]]; then
 | 
				
			||||||
 | 
					    identity="${init_script}"
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    identity=$(basename "${jarfile%.*}")_${jar_folder//\//}
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# ANSI Colors
 | 
					# ANSI Colors
 | 
				
			||||||
echoRed() { echo $'\e[0;31m'$1$'\e[0m'; }
 | 
					echoRed() { echo $'\e[0;31m'$1$'\e[0m'; }
 | 
				
			||||||
echoGreen() { echo $'\e[0;32m'$1$'\e[0m'; }
 | 
					echoGreen() { echo $'\e[0;32m'$1$'\e[0m'; }
 | 
				
			||||||
| 
						 | 
					@ -37,17 +78,6 @@ isRunning() {
 | 
				
			||||||
  ps -p $1 &> /dev/null
 | 
					  ps -p $1 &> /dev/null
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Follow symlinks to find the real jar and detect init.d script
 | 
					 | 
				
			||||||
cd $(dirname "$0")
 | 
					 | 
				
			||||||
[[ -z "$jarfile" ]] && jarfile=$(pwd)/$(basename "$0")
 | 
					 | 
				
			||||||
while [[ -L "$jarfile" ]]; do
 | 
					 | 
				
			||||||
  [[ "$jarfile" =~ "init.d" ]] && init_script=$(basename "$jarfile")
 | 
					 | 
				
			||||||
  jarfile=$(readlink "$jarfile")
 | 
					 | 
				
			||||||
  cd $(dirname "$jarfile")
 | 
					 | 
				
			||||||
  jarfile=$(pwd)/$(basename "$jarfile")
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
cd "$WORKING_DIR"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Determine the script mode
 | 
					# Determine the script mode
 | 
				
			||||||
action="run"
 | 
					action="run"
 | 
				
			||||||
if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
 | 
					if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; then
 | 
				
			||||||
| 
						 | 
					@ -55,16 +85,6 @@ if [[ "$MODE" == "auto" && -n "$init_script" ]] || [[ "$MODE" == "service" ]]; t
 | 
				
			||||||
  shift
 | 
					  shift
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Create an identity for log/pid files
 | 
					 | 
				
			||||||
if [[ -z "$identity" ]]; then
 | 
					 | 
				
			||||||
  if [[ -n "$init_script" ]]; then
 | 
					 | 
				
			||||||
    identity="${init_script}"
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
    jar_folder=$(dirname "$jarfile")
 | 
					 | 
				
			||||||
    identity=$(basename "${jarfile%.*}")_${jar_folder//\//}
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Build the pid and log filenames
 | 
					# Build the pid and log filenames
 | 
				
			||||||
if [[ "$identity" == "$init_script" ]] || [[ "$identity" == "$APP_NAME" ]]; then
 | 
					if [[ "$identity" == "$init_script" ]] || [[ "$identity" == "$APP_NAME" ]]; then
 | 
				
			||||||
  PID_FOLDER="$PID_FOLDER/${identity}"
 | 
					  PID_FOLDER="$PID_FOLDER/${identity}"
 | 
				
			||||||
| 
						 | 
					@ -88,7 +108,7 @@ else
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Build actual command to execute
 | 
					# Build actual command to execute
 | 
				
			||||||
command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $jarfile $@"
 | 
					command="$javaexe -jar -Dsun.misc.URLClassPath.disableJarChecking=true $JAVA_OPTS $jarfile $RUN_ARGS $@"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Action functions
 | 
					# Action functions
 | 
				
			||||||
start() {
 | 
					start() {
 | 
				
			||||||
| 
						 | 
					@ -166,4 +186,3 @@ run)
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exit 0
 | 
					exit 0
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue