Skip to content

Commit

Permalink
Merge pull request #138 from sbt/wip/simplify-bash-script
Browse files Browse the repository at this point in the history
unify upstart and  system v start scripts
  • Loading branch information
muuki88 committed Jan 24, 2014
2 parents d7982dc + e0cbf19 commit 3b1d318
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ execRunner () {
echo ""
}

exec "$@"
# We Don't use "exec" here for our pids to be accurate.
"$@"
}
addJava () {
dlog "[addJava] arg = '$1'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@ test -e /etc/default/${{app_name}} && source /etc/default/${{app_name}}
source /lib/init/vars.sh
source /lib/lsb/init-functions

get_java_cmd() {
if [ -x "$JAVA_HOME/bin/java" ]; then
echo "$JAVA_HOME/bin/java"
else
echo $(which java)
fi
}

PIDFILE=/var/run/${{app_name}}.pid

if [ -z "$DAEMON_USER" ]; then
DAEMON_USER=${{daemon_user}}
fi

if [ -z "$JAVA_CMD" ]; then
JAVA_CMD=$(get_java_cmd)
fi

# smb could define some additional options in $RUN_OPTS
RUN_CMD="-cp ${{app_classpath}} ${{app_main_class}} $RUN_OPTS"
RUN_CMD="${{chdir}}/bin/${{app_name}}"


start_daemon() {
log_daemon_msg "Starting" "${{app_name}}"
start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD
start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$RUN_CMD" --start -- $RUN_OPTS
log_end_msg $?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ object JavaAppStartScript {
execScript: String,
chdir: String,
appName: String,
appMainClass: String,
appClasspath: String,
daemonUser: String,
retries: Int = 0,
retryTimeout: Int = 60): Seq[(String, String)] =
Expand All @@ -101,8 +99,6 @@ object JavaAppStartScript {
"retries" -> retries.toString,
"retryTimeout" -> retryTimeout.toString,
"app_name" -> appName,
"app_main_class" -> appMainClass,
"app_classpath" -> appClasspath,
"daemon_user" -> daemonUser)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,16 @@ object JavaServerAppPackaging {
// This one is begging for sbt 0.13 syntax...
debianScriptReplacements <<= (
maintainer in Debian, packageSummary in Debian, serverLoading in Debian, daemonUser in Debian, normalizedName,
sbt.Keys.version, defaultLinuxInstallLocation, mainClass in Compile, scriptClasspath)
map { (author, descr, loader, daemonUser, name, version, installLocation, mainClass, cp) =>
sbt.Keys.version, defaultLinuxInstallLocation)
map { (author, descr, loader, daemonUser, name, version, installLocation) =>
val appDir = installLocation + "/" + name
val appClasspath = cp.map(appDir + "/lib/" + _).mkString(":")

JavaAppStartScript.makeReplacements(
author = author,
description = descr,
execScript = name,
chdir = appDir,
appName = name,
appClasspath = appClasspath,
appMainClass = mainClass.get,
daemonUser = daemonUser)
},
// TODO - Default locations shouldn't be so hacky.
Expand Down

0 comments on commit 3b1d318

Please sign in to comment.