Skip to content

Commit

Permalink
Make startup script generic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgobbo committed Feb 12, 2025
1 parent 1828362 commit ad922ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 4 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,12 @@ dependencies {

def app_name = project.name
def app_path = '/opt/' + project.name + "/" + version
def jar_file = app_path + '/lib/' + fatJar.archiveFileName
def jarFileName = fatJar.archiveFileName.get()
def jarFilePath = "${app_path}/lib/${jarFileName}"
def sys_bin ='/usr/local/bin/'
def sys_lib ='/usr/local/lib/'

task generateRpm(type: Rpm, dependsOn: [fatJar,sourcesJar]) {
//Commented as is being executed in clean+build
//dependsOn 'clean'
//dependsOn 'fatJar'

packageName project.name
requires 'java-11-openjdk'
release = 1
Expand Down Expand Up @@ -130,14 +127,12 @@ task generateRpm(type: Rpm, dependsOn: [fatJar,sourcesJar]) {
into 'bin'
//Add version to startup script name
rename { String fileName ->
if (fileName == "startup"){
app_name + "_" + version
}
fileName == "startup" ? "${app_name}_${version}" : fileName
}
expand([
"app_name": app_name,
"app_version": version,
"jar_file": jar_file
"jar_file": jarFilePath
])
fileMode 0755
}
Expand Down
10 changes: 6 additions & 4 deletions scripts/startup
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash

# Find the latest Java in /usr/lib/jvm/
#JAVA_HOME=\$(ls -d /usr/lib/jvm/jre-* 2>/dev/null | sort -V | tail -n 1)
# Find the latest Java version (11+), ignoring Java 8 (`jre-openjdk`)
JAVA_HOME=$(ls -d /usr/lib/jvm/jre-* 2>/dev/null | grep -E 'jre-[1-9][1-9]' | sort -V | tail -n 1)
JAVA_HOME=\$(ls -d /usr/lib/jvm/jre-* 2>/dev/null | grep -E 'jre-[1-9][1-9]' | sort -V | tail -n 1)


# If JAVA_HOME is found, use its java binary; otherwise, fall back to system java
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA_CMD="$JAVA_HOME/bin/java"
if [ -x "\$JAVA_HOME/bin/java" ]; then
JAVA_CMD="\$JAVA_HOME/bin/java"
else
JAVA_CMD="java"
fi

# Run the JAR with all passed arguments
exec "$JAVA_CMD" -jar ${jar_file} "$@"
exec "\$JAVA_CMD" -jar ${jar_file} "\$@"

0 comments on commit ad922ec

Please sign in to comment.