Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting chdir to application directory. #105

Merged
merged 2 commits into from
Dec 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,47 +27,51 @@ 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 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)


private def makeDebianStartScript(
replacements: Seq[(String, String)], name: String, tmpDir: File, loader: ServerLoader): Option[File] =
if (replacements.isEmpty) None
Expand All @@ -78,15 +82,13 @@ 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"
IO.write(script, scriptBits)
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"
Expand Down