From 4db2ef6da0293529b8d2762e34b4c82afdf79f01 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Tue, 10 Dec 2013 22:50:18 +0100 Subject: [PATCH 1/2] Setting chdir to application directory. So logs get placed in the right place (in play applications). Not relative to the /bin folder. --- .../sbt/packager/archetypes/upstart-template | 6 +-- .../archetypes/JavaServerApplication.scala | 53 +++++++++---------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/upstart-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/upstart-template index ba5d16635..643fb9305 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/upstart-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/upstart-template @@ -15,12 +15,10 @@ start on runlevel [2345] respawn respawn limit ${{retries}} ${{retryTimeout}} -# TODO - this wasn't working on my ubuntu... # set the working directory of the job processes -#chdir ${{chdir}} +chdir ${{chdir}} # Start the process script - cd ${{chdir}} - exec ${{exec}} + exec ./bin/${{exec}} end script \ 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 e02dbcef8..730c3a0dc 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -6,7 +6,7 @@ import Keys._ import sbt._ import sbt.Keys.{ target, mainClass, normalizedName } import SbtNativePackager._ -import com.typesafe.sbt.packager.linux.{LinuxFileMetaData, LinuxPackageMapping} +import com.typesafe.sbt.packager.linux.{ LinuxFileMetaData, LinuxPackageMapping } /** * This class contains the default settings for creating and deploying an archetypical Java application. @@ -27,47 +27,44 @@ object JavaServerAppPackaging { Seq( debianStartScriptReplacements <<= ( maintainer in Debian, packageSummary in Debian, serverLoading in Debian, daemonUser in Debian, normalizedName, - sbt.Keys.version, defaultLinuxInstallLocation, mainClass in Compile, scriptClasspath) + sbt.Keys.version, defaultLinuxInstallLocation, mainClass in Compile, scriptClasspath) map { (author, descr, loader, daemonUser, name, version, installLocation, mainClass, cp) => - // TODO name-version is copied from UniversalPlugin. This should be consolidated into a setting (install location...) - val appDir = installLocation + "/" + name - val chdir = appDir + "/bin" - val appClasspath = cp.map(appDir + "/lib/" + _).mkString(":") + // TODO name-version is copied from UniversalPlugin. This should be consolidated into a setting (install location...) + val appDir = installLocation + "/" + name + val appClasspath = cp.map(appDir + "/lib/" + _).mkString(":") - JavaAppStartScript.makeReplacements( - author = author, - description = descr, - execScript = name, - chdir = chdir, - appName = name, - appClasspath = appClasspath, - appMainClass = mainClass.get, - daemonUser = daemonUser - ) - }, + JavaAppStartScript.makeReplacements( + author = author, + description = descr, + execScript = name, + chdir = appDir, + appName = name, + appClasspath = appClasspath, + appMainClass = mainClass.get, + daemonUser = daemonUser) + }, debianMakeStartScript <<= (debianStartScriptReplacements, normalizedName, target in Universal, serverLoading in Debian) map makeDebianStartScript, debianMakeEtcDefault <<= (normalizedName, target in Universal, serverLoading in Debian) map makeEtcDefaultScript, - linuxPackageMappings in Debian <++= (debianMakeEtcDefault, normalizedName) map {(conf, name) => + linuxPackageMappings in Debian <++= (debianMakeEtcDefault, normalizedName) map { (conf, name) => conf.map(c => LinuxPackageMapping(Seq(c -> s"/etc/default/$name")).withConfig()).toSeq }, linuxPackageMappings in Debian <++= (debianMakeStartScript, normalizedName, serverLoading in Debian) map { (script, name, loader) => - val (path, permissions) = loader match { - case Upstart => ("/etc/init/" + name + ".conf", "0644") - case SystemV => ("/etc/init.d/" + name, "0755") - } + val (path, permissions) = loader match { + case Upstart => ("/etc/init/" + name + ".conf", "0644") + case SystemV => ("/etc/init.d/" + name, "0755") + } - for { - s <- script.toSeq - } yield LinuxPackageMapping(Seq(s -> path)).withPerms(permissions) - }, + for { + s <- script.toSeq + } yield LinuxPackageMapping(Seq(s -> path)).withPerms(permissions) + }, // TODO - only make these if the upstart config exists... debianMakePrermScript <<= (normalizedName, target in Universal) map makeDebianPrermScript, debianMakePostinstScript <<= (normalizedName, target in Universal, serverLoading in Debian) map makeDebianPostinstScript) - private def makeDebianStartScript( replacements: Seq[(String, String)], name: String, tmpDir: File, loader: ServerLoader): Option[File] = if (replacements.isEmpty) None @@ -78,7 +75,6 @@ object JavaServerAppPackaging { Some(script) } - protected def makeDebianPrermScript(name: String, tmpDir: File): Option[File] = { val scriptBits = JavaAppStartScript.generatePrerm(name) val script = tmpDir / "tmp" / "bin" / "debian-prerm" @@ -86,7 +82,6 @@ object JavaServerAppPackaging { Some(script) } - protected def makeDebianPostinstScript(name: String, tmpDir: File, loader: ServerLoader): Option[File] = { val scriptBits = JavaAppStartScript.generatePostinst(name, loader) val script = tmpDir / "tmp" / "bin" / "debian-postinst" From 9f3c8f68670abc3d088a634e7da431df4bc2266b Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Tue, 10 Dec 2013 23:26:16 +0100 Subject: [PATCH 2/2] Adding /var/log/ directory and symlink to logging location --- .../sbt/packager/archetypes/JavaServerApplication.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 730c3a0dc..680d9bd20 100644 --- a/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala +++ b/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala @@ -6,7 +6,7 @@ import Keys._ import sbt._ import sbt.Keys.{ target, mainClass, normalizedName } import SbtNativePackager._ -import com.typesafe.sbt.packager.linux.{ LinuxFileMetaData, LinuxPackageMapping } +import com.typesafe.sbt.packager.linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink } /** * This class contains the default settings for creating and deploying an archetypical Java application. @@ -61,6 +61,13 @@ object JavaServerAppPackaging { s <- script.toSeq } yield LinuxPackageMapping(Seq(s -> path)).withPerms(permissions) }, + // TODO the /var/log should be generalized like defaultLinuxInstallLocation + linuxPackageMappings in Debian <+= (normalizedName) map { + name => packageTemplateMapping("/var/log/" + name)() + }, + linuxPackageSymlinks in Debian <+= (normalizedName, defaultLinuxInstallLocation) map { + (name, install) => LinuxSymlink(install + "/" + name + "/logs", "/var/log/" + name) + }, // TODO - only make these if the upstart config exists... debianMakePrermScript <<= (normalizedName, target in Universal) map makeDebianPrermScript, debianMakePostinstScript <<= (normalizedName, target in Universal, serverLoading in Debian) map makeDebianPostinstScript)