Skip to content

Commit 3b1d318

Browse files
committed
Merge pull request #138 from sbt/wip/simplify-bash-script
unify upstart and system v start scripts
2 parents d7982dc + e0cbf19 commit 3b1d318

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

src/main/resources/com/typesafe/sbt/packager/archetypes/bash-template

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ execRunner () {
127127
echo ""
128128
}
129129

130-
exec "$@"
130+
# We Don't use "exec" here for our pids to be accurate.
131+
"$@"
131132
}
132133
addJava () {
133134
dlog "[addJava] arg = '$1'"

src/main/resources/com/typesafe/sbt/packager/archetypes/systemv/start-template

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,21 @@ test -e /etc/default/${{app_name}} && source /etc/default/${{app_name}}
1313
source /lib/init/vars.sh
1414
source /lib/lsb/init-functions
1515

16-
get_java_cmd() {
17-
if [ -x "$JAVA_HOME/bin/java" ]; then
18-
echo "$JAVA_HOME/bin/java"
19-
else
20-
echo $(which java)
21-
fi
22-
}
2316

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

2619
if [ -z "$DAEMON_USER" ]; then
2720
DAEMON_USER=${{daemon_user}}
2821
fi
2922

30-
if [ -z "$JAVA_CMD" ]; then
31-
JAVA_CMD=$(get_java_cmd)
32-
fi
3323

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

3727

3828
start_daemon() {
3929
log_daemon_msg "Starting" "${{app_name}}"
40-
start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD
30+
start-stop-daemon --background --chdir ${{chdir}} --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$RUN_CMD" --start -- $RUN_OPTS
4131
log_end_msg $?
4232
}
4333

src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppUpstartScript.scala

-4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ object JavaAppStartScript {
8888
execScript: String,
8989
chdir: String,
9090
appName: String,
91-
appMainClass: String,
92-
appClasspath: String,
9391
daemonUser: String,
9492
retries: Int = 0,
9593
retryTimeout: Int = 60): Seq[(String, String)] =
@@ -101,8 +99,6 @@ object JavaAppStartScript {
10199
"retries" -> retries.toString,
102100
"retryTimeout" -> retryTimeout.toString,
103101
"app_name" -> appName,
104-
"app_main_class" -> appMainClass,
105-
"app_classpath" -> appClasspath,
106102
"daemon_user" -> daemonUser)
107103
}
108104

src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala

+2-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,16 @@ object JavaServerAppPackaging {
3333
// This one is begging for sbt 0.13 syntax...
3434
debianScriptReplacements <<= (
3535
maintainer in Debian, packageSummary in Debian, serverLoading in Debian, daemonUser in Debian, normalizedName,
36-
sbt.Keys.version, defaultLinuxInstallLocation, mainClass in Compile, scriptClasspath)
37-
map { (author, descr, loader, daemonUser, name, version, installLocation, mainClass, cp) =>
36+
sbt.Keys.version, defaultLinuxInstallLocation)
37+
map { (author, descr, loader, daemonUser, name, version, installLocation) =>
3838
val appDir = installLocation + "/" + name
39-
val appClasspath = cp.map(appDir + "/lib/" + _).mkString(":")
4039

4140
JavaAppStartScript.makeReplacements(
4241
author = author,
4342
description = descr,
4443
execScript = name,
4544
chdir = appDir,
4645
appName = name,
47-
appClasspath = appClasspath,
48-
appMainClass = mainClass.get,
4946
daemonUser = daemonUser)
5047
},
5148
// TODO - Default locations shouldn't be so hacky.

0 commit comments

Comments
 (0)