Skip to content

Commit

Permalink
Merge pull request #701 from kardapoltsev/wip/override-start-script
Browse files Browse the repository at this point in the history
Different start script replacements for different system loaders
  • Loading branch information
muuki88 committed Nov 28, 2015
2 parents 5f4ced3 + 1938cd3 commit 6548810
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ object JavaServerAppPackaging extends AutoPlugin {
linuxScriptReplacements += JavaServerLoaderScript.loaderFunctionsReplacement(serverLoading.value, ARCHETYPE),
linuxScriptReplacements ++= bashScriptEnvConfigLocation.value.map(ENV_CONFIG_REPLACEMENT -> _).toSeq,

linuxStartScriptTemplate := JavaServerLoaderScript(
script = startScriptName(serverLoading.value, Debian),
loader = serverLoading.value,
archetype = ARCHETYPE,
template = Option(sourceDirectory.value / "templates" / "start")
),
linuxStartScriptTemplate <<= (serverLoading in Debian, sourceDirectory) map { (loader, srcDir) =>
JavaServerLoaderScript(
script = defaultTemplateName(loader, Debian),
loader = loader,
archetype = ARCHETYPE,
template = overrideTemplate(srcDir, loader, Debian)
)
},
defaultLinuxStartScriptLocation <<= serverLoading apply getStartScriptLocation,
linuxMakeStartScript in Debian <<= (linuxStartScriptTemplate in Debian,
linuxScriptReplacements in Debian,
Expand Down Expand Up @@ -143,12 +145,14 @@ object JavaServerAppPackaging extends AutoPlugin {
daemonGroup in Rpm <<= daemonGroup in Linux,
daemonGroupGid in Rpm <<= daemonGroupGid in Linux,
// === Startscript creation ===
linuxStartScriptTemplate := JavaServerLoaderScript(
script = startScriptName((serverLoading in Rpm).value, Rpm),
loader = (serverLoading in Rpm).value,
archetype = ARCHETYPE,
template = Option(sourceDirectory.value / "templates" / "start")
),
linuxStartScriptTemplate <<= (serverLoading in Rpm, sourceDirectory) map { (loader, srcDir) =>
JavaServerLoaderScript(
script = defaultTemplateName(loader, Rpm),
loader = loader,
archetype = ARCHETYPE,
template = overrideTemplate(srcDir, loader, Rpm)
)
},
linuxMakeStartScript in Rpm <<= (linuxStartScriptTemplate in Rpm,
linuxScriptReplacements in Rpm,
target in Universal,
Expand Down Expand Up @@ -179,12 +183,17 @@ object JavaServerAppPackaging extends AutoPlugin {
/* ============ Helper Methods ============== */
/* ========================================== */

private[this] def startScriptName(loader: ServerLoader, config: Configuration): String = (loader, config.name) match {
private[this] def defaultTemplateName(loader: ServerLoader, config: Configuration): String = (loader, config.name) match {
// SystemV has two different start scripts
case (SystemV, name) => s"start-$name-template"
case _ => "start-template"
}


private[this] def overrideTemplate(sourceDirectory: File, loader: ServerLoader, config: Configuration): Option[File] = {
Option(sourceDirectory / "templates" / config.name / loader.toString.toLowerCase)
}

private[this] def makeStartScriptReplacements(
requiredStartFacilities: Option[String],
requiredStopFacilities: Option[String],
Expand Down
35 changes: 35 additions & 0 deletions src/sbt-test/debian/override-start-script/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import com.typesafe.sbt.packager.archetypes.ServerLoader

enablePlugins(JavaServerAppPackaging, JDebPackaging)

serverLoading in Debian := ServerLoader.Upstart

// TODO change this after #437 is fixed
daemonUser in Linux := "root"

daemonGroup in Linux := "app-group"

mainClass in Compile := Some("empty")

name := "debian-test"

name in Debian := "debian-test"

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."""

TaskKey[Unit]("check-startup-script") <<= (target, streams) map { (target, out) =>
val extracted = target / "tmp" / "extracted-package"
extracted.mkdirs()
Seq("dpkg-deb", "-R", (target / "debian-test_0.1.0_all.deb").absolutePath, extracted.absolutePath).!

val script = IO.read(extracted / "etc" / "init" / "debian-test.conf")
assert(script.startsWith("# right upstart template"), s"override script wasn't picked, script is\n$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 @@
# right systemV template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# right upstart template
2 changes: 2 additions & 0 deletions src/sbt-test/debian/override-start-script/src/templates/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# check that old start template isn't picked
# wrong upstart start template
6 changes: 6 additions & 0 deletions src/sbt-test/debian/override-start-script/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run the debian packaging.
> debian:packageBin
$ exists target/debian-test_0.1.0_all.deb

# Check files for defaults
> check-startup-script
13 changes: 8 additions & 5 deletions src/sphinx/archetypes/cheatsheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ the ``bashScriptExtraDefines`` that will be used in addition to the default set:



Service Manager - ``src/templates/start``
Service Manager
-----------------------------------------

Creating a file here will override either the init.d startup script or
the upstart start script. It will either be located at
``/etc/init/<application>`` or ``/etc/init.d/<application>`` depending on which
serverLoader is being used.
It's also possible to override the entire script/configuration for your service manager.
Create a file ``src/templates/$format/$loader`` and it will be used instead.

Possible values:

* ``$format`` - ``debian`` or ``rpm``
* ``$loader`` - ``upstart``, ``systemv`` or ``systemd``

**Syntax**

Expand Down
9 changes: 7 additions & 2 deletions src/sphinx/archetypes/java_server/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ which will add the following resource file to use start/stop instead of initctl
The :doc:`debian </formats/debian>` and :doc:`redhat </formats/rpm>` pages have further information on overriding
distribution specific actions.

Override Start Script - ``src/templates/start``
Override Start Script
-----------------------------------------------

It's also possible to override the entire script/configuration for your service manager.
Create a file ``src/templates/start`` and it will be used instead.
Create a file ``src/templates/$format/$loader`` and it will be used instead.

Possible values:

* ``$format`` - ``debian`` or ``rpm``
* ``$loader`` - ``upstart``, ``systemv`` or ``systemd``

**Syntax**

Expand Down

0 comments on commit 6548810

Please sign in to comment.