Skip to content

Commit

Permalink
FIX #217 Introduced executableScriptName setting
Browse files Browse the repository at this point in the history
  • Loading branch information
muuki88 committed Jul 25, 2014
1 parent 05208e1 commit 22a691a
Show file tree
Hide file tree
Showing 37 changed files with 241 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires=${{start_facilities}}
[Service]
Type=simple
WorkingDirectory=${{chdir}}
ExecStart=${{chdir}}/bin/${{app_name}}
ExecStart=${{chdir}}/bin/${{exec}}
Restart=always
RestartSec=${{retryTimeout}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Requires=${{start_facilities}}
[Service]
Type=simple
WorkingDirectory=${{chdir}}
ExecStart=${{chdir}}/bin/${{app_name}}
ExecStart=${{chdir}}/bin/${{exec}}
Restart=always
RestartSec=${{retryTimeout}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if [ -z "$DAEMON_USER" ]; then
fi


RUN_CMD="${{chdir}}/bin/${{app_name}}"
RUN_CMD="${{chdir}}/bin/${{exec}}"


start_daemon() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Source function library.
. /etc/rc.d/init.d/functions

prog="${{app_name}}"
prog="${{exec}}"

# FIXME The pid file should be handled by the executed script
# The pid can be filled in in this script
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/com/typesafe/sbt/PackagerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ object SbtNativePackager extends Plugin
NativePackagerKeys.maintainer := "",
NativePackagerKeys.packageDescription := "",
NativePackagerKeys.packageSummary := "",
packageName <<= normalizedName
NativePackagerKeys.packageName <<= normalizedName,
NativePackagerKeys.executableScriptName <<= NativePackagerKeys.packageName
)

import SettingsHelper._
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Keys extends linux.Keys

// These keys are used by the JavaApp/JavaServer archetypes.
val packageName = SettingKey[String]("packageName", "Name of the created output package. Used for dirs/scripts.")
val executableScriptName = SettingKey[String]("executableScriptName", "Name of the executing script.")
val makeBashScript = TaskKey[Option[File]]("makeBashScript", "Creates or discovers the bash script used by this project.")
val bashScriptDefines = TaskKey[Seq[String]]("bashScriptDefines", "A list of definitions that should be written to the bash file template.")
val bashScriptExtraDefines = TaskKey[Seq[String]]("bashScriptExtraDefines", "A list of extra definitions that should be written to the bash file template.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package archetypes
import Keys._
import sbt._
import sbt.Project.Initialize
import sbt.Keys.{ mappings, target, name, mainClass, normalizedName, sourceDirectory }
import sbt.Keys.{ mappings, target, name, mainClass, sourceDirectory }
import com.typesafe.sbt.packager.linux.{ LinuxFileMetaData, LinuxPackageMapping }
import SbtNativePackager._

Expand Down Expand Up @@ -45,21 +45,21 @@ object JavaAppPackaging {
hasMain getOrElse Nil
},
// TODO - Overridable bash template.
makeBashScript <<= (bashScriptDefines, target in Universal, packageName, sourceDirectory) map makeUniversalBinScript,
makeBashScript <<= (bashScriptDefines, target in Universal, executableScriptName, sourceDirectory) map makeUniversalBinScript,
batScriptExtraDefines := Nil,
batScriptReplacements <<= (normalizedName, Keys.mainClass in Compile, scriptClasspath, batScriptExtraDefines) map { (name, mainClass, cp, extras) =>
batScriptReplacements <<= (packageName, Keys.mainClass in Compile, scriptClasspath, batScriptExtraDefines) map { (name, mainClass, cp, extras) =>
mainClass map { mc =>
JavaAppBatScript.makeReplacements(name = name, mainClass = mc, appClasspath = cp, extras = extras)
} getOrElse Nil

},
makeBatScript <<= (batScriptReplacements, target in Universal, packageName, sourceDirectory) map makeUniversalBatScript,
mappings in Universal <++= (makeBashScript, packageName) map { (script, name) =>
makeBatScript <<= (batScriptReplacements, target in Universal, executableScriptName, sourceDirectory) map makeUniversalBatScript,
mappings in Universal <++= (makeBashScript, executableScriptName) map { (script, name) =>
for {
s <- script.toSeq
} yield s -> ("bin/" + name)
},
mappings in Universal <++= (makeBatScript, packageName) map { (script, name) =>
mappings in Universal <++= (makeBatScript, executableScriptName) map { (script, name) =>
for {
s <- script.toSeq
} yield s -> ("bin/" + name + ".bat")
Expand Down Expand Up @@ -164,7 +164,7 @@ object JavaAppPackaging {
!(name.endsWith(".jar") || name.endsWith("-sources.jar") || name.endsWith("-javadoc.jar"))
}

def findProjectDependencyArtifacts: Initialize[Task[Seq[Attributed[File]]]] =
def findProjectDependencyArtifacts: Def.Initialize[Task[Seq[Attributed[File]]]] =
(sbt.Keys.buildDependencies, sbt.Keys.thisProjectRef, sbt.Keys.state) apply { (build, thisProject, stateTask) =>
val refs = thisProject +: dependencyProjectRefs(build, thisProject)
// Dynamic lookup of dependencies...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package debian

import Keys._
import sbt._
import sbt.Keys.{ target, name, normalizedName, TaskStreams }
import sbt.Keys.{ target, name, TaskStreams }
import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink }
import linux.Keys.{ linuxScriptReplacements, daemonShell }
import com.typesafe.sbt.packager.Hashing
Expand All @@ -28,6 +28,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin with NativePackaging wi
target in Debian <<= (target, name in Debian, version in Debian) apply ((t, n, v) => t / (n + "-" + v)),
name in Debian <<= (name in Linux),
packageName in Debian <<= (packageName in Linux),
executableScriptName in Debian <<= (executableScriptName in Linux),
version in Debian <<= (version in Linux),
linuxPackageMappings in Debian <<= linuxPackageMappings,
packageDescription in Debian <<= packageDescription in Linux,
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ object Keys extends DebianKeys {
// Metadata keys
def name = sbt.Keys.name
def packageName = linux.Keys.packageName
def executableScriptName = linux.Keys.executableScriptName
def version = sbt.Keys.version
def maintainer = linux.Keys.maintainer
def packageArchitecture = linux.Keys.packageArchitecture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sbt._
trait DockerPlugin extends Plugin with UniversalPlugin {
val Docker = config("docker") extend Universal

private[this] final def makeDockerContent(dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, name: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String]) = {
private[this] final def makeDockerContent(dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, execScript: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String]) = {
val headerCommands = Seq(
Cmd("FROM", dockerBaseImage),
Cmd("MAINTAINER", maintainer)
Expand All @@ -19,7 +19,7 @@ trait DockerPlugin extends Plugin with UniversalPlugin {
Cmd("WORKDIR", "%s" format dockerBaseDirectory),
ExecCmd("RUN", "chown", "-R", daemonUser, "."),
Cmd("USER", daemonUser),
ExecCmd("ENTRYPOINT", "bin/%s" format name),
ExecCmd("ENTRYPOINT", "bin/%s" format execScript),
ExecCmd("CMD")
)

Expand Down Expand Up @@ -49,8 +49,8 @@ trait DockerPlugin extends Plugin with UniversalPlugin {
}

private[this] final def generateDockerConfig(
dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, packageName: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String], target: File) = {
val dockerContent = makeDockerContent(dockerBaseImage, dockerBaseDirectory, maintainer, daemonUser, packageName, exposedPorts, exposedVolumes)
dockerBaseImage: String, dockerBaseDirectory: String, maintainer: String, daemonUser: String, execScript: String, exposedPorts: Seq[Int], exposedVolumes: Seq[String], target: File) = {
val dockerContent = makeDockerContent(dockerBaseImage, dockerBaseDirectory, maintainer, daemonUser, execScript, exposedPorts, exposedVolumes)

val f = target / "Dockerfile"
IO.write(f, dockerContent)
Expand Down Expand Up @@ -150,14 +150,15 @@ trait DockerPlugin extends Plugin with UniversalPlugin {
dockerBaseImage := "dockerfile/java",
name in Docker <<= name,
packageName in Docker <<= packageName,
executableScriptName in Docker <<= executableScriptName,
dockerRepository := None,
sourceDirectory in Docker <<= sourceDirectory apply (_ / "docker"),
target in Docker <<= target apply (_ / "docker"),

// TODO this must be changed, when there is a setting for the startScripts name
dockerGenerateConfig <<=
(dockerBaseImage in Docker, defaultLinuxInstallLocation in Docker, maintainer in Docker, daemonUser in Docker,
packageName /* this is not scoped!*/ , dockerExposedPorts in Docker, dockerExposedVolumes in Docker, target in Docker) map
executableScriptName /* this is not scoped!*/ , dockerExposedPorts in Docker, dockerExposedVolumes in Docker, target in Docker) map
generateDockerConfig
) ++ mapGenericFilesToDocker ++ inConfig(Docker)(Seq(
daemonUser := "daemon",
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/typesafe/sbt/packager/docker/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object Keys extends DockerKeys {
def mappings = sbt.Keys.mappings
def name = sbt.Keys.name
def packageName = universal.Keys.packageName
def normalizedName = universal.Keys.normalizedName
def executableScriptName = universal.Keys.executableScriptName
def stage = universal.Keys.stage
def publish = sbt.Keys.publish
def publishArtifact = sbt.Keys.publishArtifact
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ trait Keys {
object Keys extends Keys {
def name = sbt.Keys.name
def packageName = packager.Keys.packageName
def normalizedName = sbt.Keys.normalizedName
def executableScriptName = packager.Keys.executableScriptName
def sourceDirectory = sbt.Keys.sourceDirectory
}
11 changes: 6 additions & 5 deletions src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ trait LinuxPlugin extends Plugin {
packageDescription in Linux <<= packageDescription,
name in Linux <<= name,
packageName in Linux <<= packageName,
normalizedName in Linux <<= (name in Linux) apply Project.normalizeModuleID,
daemonUser in Linux <<= normalizedName in Linux,
executableScriptName in Linux <<= executableScriptName,
daemonUser in Linux <<= packageName in Linux,
daemonGroup in Linux <<= daemonUser in Linux,
daemonShell in Linux := "/bin/false",
defaultLinuxInstallLocation := "/usr/share",
Expand All @@ -47,16 +47,17 @@ trait LinuxPlugin extends Plugin {
linuxJavaAppStartScriptBuilder := JavaAppStartScript.Debian,
// This one is begging for sbt 0.13 syntax...
linuxScriptReplacements <<= (
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux, normalizedName in Linux,
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux,
packageName in Linux, executableScriptName in Linux,
sbt.Keys.version, defaultLinuxInstallLocation, linuxJavaAppStartScriptBuilder)
apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, version, installLocation, builder) =>
apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, execScript, version, installLocation, builder) =>
val appDir = installLocation + "/" + name

// TODO Making replacements should be done somewhere else. Maybe TemplateWriter
builder.makeReplacements(
author = author,
description = descr,
execScript = name,
execScript = execScript,
chdir = appDir,
appName = name,
daemonUser = daemonUser,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/typesafe/sbt/packager/rpm/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object Keys extends RpmKeys {
// METADATA keys.
def name = sbt.Keys.name
def packageName = packager.Keys.packageName
def normalizedName = sbt.Keys.normalizedName
def executableScriptName = linux.Keys.executableScriptName
def version = sbt.Keys.version
def maintainer = linux.Keys.maintainer
def packageArchitecture = linux.Keys.packageArchitecture
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ trait RpmPlugin extends Plugin with LinuxPlugin {
packageDescription in Rpm <<= packageDescription in Linux,
target in Rpm <<= target(_ / "rpm"),
name in Rpm <<= name in Linux,
packageName in Rpm <<= packageName in Linux
packageName in Rpm <<= packageName in Linux,
executableScriptName in Rpm <<= executableScriptName in Linux
) ++ inConfig(Rpm)(Seq(
normalizedName <<= name apply Project.normalizeModuleID,
packageArchitecture := "noarch",
rpmMetadata <<=
(packageName, version, rpmRelease, rpmPrefix, packageArchitecture, rpmVendor, rpmOs, packageSummary, packageDescription, rpmAutoprov, rpmAutoreq) apply RpmMetadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Keys extends UniversalKeys {
def packageDoc = sbt.Keys.packageDoc
def name = sbt.Keys.name
def packageName = packager.Keys.packageName
def normalizedName = sbt.Keys.normalizedName
def executableScriptName = packager.Keys.executableScriptName
def target = sbt.Keys.target
def sourceDirectory = sbt.Keys.sourceDirectory
def streams = sbt.Keys.streams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ trait UniversalPlugin extends Plugin {
name in Universal <<= name,
name in UniversalDocs <<= name in Universal,
name in UniversalSrc <<= name in Universal,
packageName in Universal <<= packageName
packageName in Universal <<= packageName,
executableScriptName in Universal <<= executableScriptName
) ++
makePackageSettingsForConfig(Universal) ++
makePackageSettingsForConfig(UniversalDocs) ++
Expand All @@ -38,7 +39,6 @@ trait UniversalPlugin extends Plugin {
makePackageSettings(packageZipTarball, config)(makeTgz) ++
makePackageSettings(packageXzTarball, config)(makeTxz) ++
inConfig(config)(Seq(
normalizedName <<= name apply Project.normalizeModuleID,
packageName <<= (packageName, version) apply (_ + "-" + _),
mappings <<= sourceDirectory map findSources,
dist <<= (packageBin, streams) map printDist,
Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/com/typesafe/sbt/packager/windows/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ trait WindowsKeys {
val wixProductConfig = TaskKey[xml.Node]("wix-product-xml", "The WIX XML configuration for a product (nested in Wix/Product elements).")
val wixConfig = TaskKey[xml.Node]("wix-xml", "The WIX XML configuration for this package.")
val wixFile = TaskKey[File]("wix-file", "The WIX XML file to package with.")
@deprecated("use packageBin instead!")
@deprecated("use packageBin instead!", "0.7.0")
val packageMsi = TaskKey[File]("package-msi", "creates a new windows CAB file containing everything for the installation.")
val candleOptions = SettingKey[Seq[String]]("candle-options", "Options to pass to the candle.exe program.")
val lightOptions = SettingKey[Seq[String]]("light-options", "Options to pass to the light.exe program.")
Expand All @@ -25,11 +25,12 @@ object Keys extends WindowsKeys {
def target = sbt.Keys.target
def mappings = sbt.Keys.mappings
def name = sbt.Keys.name
def packageName = packager.Keys.packageName
def executableScriptName = packager.Keys.executableScriptName
def streams = sbt.Keys.streams
def sourceDirectory = sbt.Keys.sourceDirectory
def packageBin = sbt.Keys.packageBin
// TODO - move this somewhere generic.
def maintainer = linux.Keys.maintainer
def packageSummary = linux.Keys.packageSummary
def packageDescription = linux.Keys.packageDescription
def maintainer = packager.Keys.maintainer
def packageSummary = packager.Keys.packageSummary
def packageDescription = packager.Keys.packageDescription
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package windows

import Keys._
import sbt._
import sbt.Keys.{ normalizedName }

trait WindowsPlugin extends Plugin {
val Windows = config("windows")
Expand All @@ -13,6 +14,7 @@ trait WindowsPlugin extends Plugin {
target in Windows <<= target apply (_ / "windows"),
// TODO - Should this use normalized name like the linux guys?
name in Windows <<= name,
packageName in Windows <<= normalizedName,
// Defaults so that our simplified building works
candleOptions := Seq("-ext", "WixUtilExtension"),
lightOptions := Seq("-ext", "WixUIExtension",
Expand Down
29 changes: 29 additions & 0 deletions src/sbt-test/debian/test-executableScriptName/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import NativePackagerKeys._

packagerSettings

packageArchetype.java_server

name := "debian-test"

executableScriptName := "debian-exec"

version := "0.1.0"

maintainer := "Josh Suereth <joshua.suereth@typesafe.com>"

packageSummary := "Test debian package"

packageDescription := """A fun package description of our software,
with multiple lines."""

debianPackageDependencies in Debian ++= Seq("java2-runtime", "bash (>= 2.05a-11)")

debianPackageRecommends in Debian += "git"

TaskKey[Unit]("check-upstart-script") <<= (target, streams) map { (target, out) =>
val script = IO.read(target / "debian-test-0.1.0" / "etc" / "init" / "debian-test.conf")
assert(script.contains("exec ./bin/debian-exec"), "wrong exec call\n" + script)
out.log.success("Successfully tested control script")
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package test

object Main {
def main (args: Array[String]) {
//server app imitation
while (true){
Thread.sleep(1000L)
}
}
}
18 changes: 18 additions & 0 deletions src/sbt-test/debian/test-executableScriptName/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Run the debian packaging.
> debian:package-bin
$ exists target/debian-test_0.1.0_all.deb
# Testing the packageName configuration
$ exists target/debian-test-0.1.0/DEBIAN
$ exists target/debian-test-0.1.0/DEBIAN/control
# --------------------------------------------
$ exists target/debian-test-0.1.0/usr/
$ exists target/debian-test-0.1.0/usr/share/
$ exists target/debian-test-0.1.0/usr/share/debian-test/
$ exists target/debian-test-0.1.0/usr/share/debian-test/bin/
$ exists target/debian-test-0.1.0/usr/share/debian-test/bin/debian-exec
$ exists target/debian-test-0.1.0/var/log/debian-test/
$ exists target/debian-test-0.1.0/var/run/debian-test/
$ exists target/debian-test-0.1.0/etc/default/debian-test/
# --------------------------------------------
$ exists target/debian-test-0.1.0/etc/init/debian-test.conf
> check-upstart-script
21 changes: 21 additions & 0 deletions src/sbt-test/docker/test-executableScriptName/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._

packageArchetype.java_application

name := "docker-test"

packageName in Docker := "docker-package"

executableScriptName := "docker-exec"

version := "0.1.0"

maintainer := "Gary Coady <gary@lyranthe.org>"

TaskKey[Unit]("check-dockerfile") <<= (target, streams) map { (target, out) =>
val dockerfile = IO.read(target / "docker" / "Dockerfile")
assert(dockerfile.contains("ENTRYPOINT [\"bin/docker-exec\"]\n"), "dockerfile doesn't contain ENTRYPOINT [\"docker-exec\"]\n" + dockerfile)
out.log.success("Successfully tested control script")
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Loading

0 comments on commit 22a691a

Please sign in to comment.