From d13440b98886486642041f97c0b787408918f7e1 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Tue, 28 Jan 2014 23:56:09 +0100 Subject: [PATCH 1/2] Fix #98 java server type includes /etc/default by default * Added default configuration location * Added replacements in /etc/default configuration * Added tests * Added default configuration file with examples * Added /etc/default script to Upstart --- .../packager/archetypes/etc-default-template | 38 +++++++++++++++++-- .../archetypes/JavaServerApplication.scala | 18 ++++----- src/sbt-test/debian/sysvinit-deb/test | 1 + src/sbt-test/debian/upstart-deb/test | 2 + 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template index 2cd74fe08..beacd145b 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template @@ -1,4 +1,34 @@ -#Some start script options could be overridden here -#RUN_OPTS="" -#DAEMON_USER="" -#JAVA_CMD="" \ No newline at end of file +# ################################# +# ##### Default configuration ##### +# ################################# + +# Available replacements +# ------------------------------------------------ +# ${{author}} debian author +# ${{descr}} debian package description +# ${{exec}} startup script name +# ${{chdir}} app directory +# ${{retries}} retries for startup +# ${{retryTimeout}} retry timeout +# ${{app_name}} normalized app name +# ${{daemon_user}} daemon user +# ------------------------------------------------- + +# Setting -Xmx and -Xms in Megabyte +# -mem 1024 + +# Setting -X directly (-J is stripped) +# -J-X +# -J-Xmx 1024 + +# Add additional jvm parameters +# -Dkey=val + +# For play applications you may set +# -Dpidfile.path=/var/run/${{app_name}}.pid + +# Turn on JVM debugging, open at the given port +# -jvm-debug + +# Don't run the java version check +# -no-version-check \ No newline at end of file diff --git a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala index 0382ff057..43c8ff236 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -67,12 +67,13 @@ object JavaServerAppPackaging { }, // === etc config mapping === + bashScriptConfigLocation <<= normalizedName map (name => Some("/etc/default/" + name)), linuxEtcDefaultTemplate in Debian <<= sourceDirectory map { dir => val overrideScript = dir / "templates" / "etc-default" if (overrideScript.exists) overrideScript.toURI.toURL else etcDefaultTemplateSource }, - debianMakeEtcDefault <<= (normalizedName, target in Universal, serverLoading in Debian, linuxEtcDefaultTemplate in Debian) + debianMakeEtcDefault <<= (normalizedName, target in Universal, linuxEtcDefaultTemplate in Debian, debianScriptReplacements) map makeEtcDefaultScript, linuxPackageMappings in Debian <++= (debianMakeEtcDefault, normalizedName) map { (conf, name) => conf.map(c => LinuxPackageMapping(Seq(c -> ("/etc/default/" + name))).withConfig()).toSeq @@ -106,15 +107,10 @@ object JavaServerAppPackaging { } } - protected def makeEtcDefaultScript(name: String, tmpDir: File, loader: ServerLoader, source: java.net.URL): Option[File] = { - loader match { - case Upstart => None - case SystemV => { - val scriptBits = TemplateWriter.generateScript(source, Seq.empty) - val script = tmpDir / "tmp" / "etc" / "default" / name - IO.write(script, scriptBits) - Some(script) - } - } + protected def makeEtcDefaultScript(name: String, tmpDir: File, source: java.net.URL, replacements: Seq[(String, String)]): Option[File] = { + val scriptBits = TemplateWriter.generateScript(source, replacements) + val script = tmpDir / "tmp" / "etc" / "default" / name + IO.write(script, scriptBits) + Some(script) } } diff --git a/src/sbt-test/debian/sysvinit-deb/test b/src/sbt-test/debian/sysvinit-deb/test index b7ae637c9..fd7134df0 100644 --- a/src/sbt-test/debian/sysvinit-deb/test +++ b/src/sbt-test/debian/sysvinit-deb/test @@ -3,4 +3,5 @@ $ exists target/debian-test-0.1.0.deb $ exists target/debian-test-0.1.0/etc +$ exists target/debian-test-0.1.0/etc/default/debian-test $ exists target/debian-test-0.1.0/etc/init.d/debian-test diff --git a/src/sbt-test/debian/upstart-deb/test b/src/sbt-test/debian/upstart-deb/test index 0cfa652ca..4949f1a21 100644 --- a/src/sbt-test/debian/upstart-deb/test +++ b/src/sbt-test/debian/upstart-deb/test @@ -3,7 +3,9 @@ $ exists target/debian-test-0.1.0.deb $ exists target/debian-test-0.1.0/etc +$ exists target/debian-test-0.1.0/etc/default/debian-test $ exists target/debian-test-0.1.0/etc/init/debian-test.conf + # Check defaults $ exists target/debian-test-0.1.0/DEBIAN/prerm $ exists target/debian-test-0.1.0/DEBIAN/postinst From 114403d1c806c0b50ec68c8b5ef13b523cf2e410 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Wed, 29 Jan 2014 20:02:12 +0100 Subject: [PATCH 2/2] Correcting etc-default file --- .../com/typesafe/sbt/packager/archetypes/etc-default-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template index beacd145b..d79474746 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/etc-default-template @@ -19,7 +19,7 @@ # Setting -X directly (-J is stripped) # -J-X -# -J-Xmx 1024 +# -J-Xmx1024 # Add additional jvm parameters # -Dkey=val