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

Allow custom templates to be provided separately for each template #938

Merged
merged 4 commits into from
Feb 8, 2017
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 @@ -71,5 +71,5 @@ package object systemloader {
loader.toString + "/" + name

private def overrideFromFile(sourceDirectory: File, loader: ServerLoader, name: String): Option[URL] =
Option(sourceDirectory / "templates" / "systemloader" / loader.toString).filter(_.exists).map(_.toURI.toURL)
Option(sourceDirectory / "templates" / "systemloader" / loader.toString / name).filter(_.exists).map(_.toURI.toURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. This quite some bug. Along with 6 tests that tested the wrong implementation:

[error] (*:scripted) Failed tests:
[error] 	rpm / override-start-script-systemd
[error] 	rpm / override-start-script-systemv
[error] 	rpm / override-start-script-upstart
[error] 	debian / override-start-script-systemd
[error] 	debian / override-start-script-systemv
[error] 	debian / override-start-script-upstart

}
27 changes: 27 additions & 0 deletions src/sbt-test/debian/override-loader-functions/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
enablePlugins(JavaServerAppPackaging, JDebPackaging, SystemdPlugin)

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

mainClass in Compile := Some("empty")

name := "debian-test"
version := "0.1.0"
maintainer := "Mitch Seymour <[email protected]>"

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

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

val script = IO.read(extracted / "postinst")

assert(script.contains("# right systemd template"), s"override script wasn't picked, script is\n$script")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks that the loader-functions has be correctly inserted. I think this check is enough, even though I wouldn't my checking that the wrong systemd template isn't contained in the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added such an assertion

assert(!script.contains("wrong systemd start template"), s"script contained wrong template, script is\n$script")
()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))

libraryDependencies += "org.vafer" % "jdeb" % "1.3" artifacts (Artifact("jdeb", "jar", "jar"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# check that old start template isn't picked
# wrong systemd start template
6 changes: 6 additions & 0 deletions src/sbt-test/debian/override-loader-functions/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-loader-functions
33 changes: 33 additions & 0 deletions src/sbt-test/rpm/override-loader-functions/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
enablePlugins(JavaServerAppPackaging, SystemdPlugin)

name := "rpm-test"

version := "0.1.0"

maintainer := "Mitch Seymour <[email protected]>"

packageSummary := "Test rpm package"

executableScriptName := "rpm-exec"

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

rpmRelease := "1"

rpmVendor := "typesafe"

rpmUrl := Some("http://github.com/sbt/sbt-native-packager")

rpmLicense := Some("BSD")

rpmGroup := Some("test-group")

TaskKey[Unit]("check-loader-script") <<= (target, streams) map { (target, out) =>
val path = target / "rpm"/ "RPMS" / "noarch" / "rpm-test-0.1.0-1.noarch.rpm"
val scripts = s"rpm -qp --scripts ${path.absolutePath}".!!

assert(scripts.contains("# right systemd template"), s"override script wasn't picked, scripts are\n$scripts")
assert(!scripts.contains("wrong start template"), s"scripts contained wrong template, scripts are\n$scripts")
()
}
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,2 @@
# check that old start template isn't picked
# wrong start template
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# right systemd template
5 changes: 5 additions & 0 deletions src/sbt-test/rpm/override-loader-functions/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run the rpm packaging.
> rpm:package-bin
$ exists target/rpm/RPMS/noarch/rpm-test-0.1.0-1.noarch.rpm

> check-loader-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# right systemd template
11 changes: 8 additions & 3 deletions src/sphinx/archetypes/cheatsheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,20 @@ the ``bashScriptExtraDefines`` that will be used in addition to the default set:



Service Manager
Service Manager Templates
-----------------------------------------

It's also possible to override the entire script/configuration for your service manager.
Create a file ``src/templates/systemloader/$loader`` and it will be used instead.
It's also possible to override the entire script/configuration templates for your service manager.
These templates vary by loader type. Create a file ``src/templates/systemloader/$loader/$template``
and it will be used instead.

Possible values:

* ``$loader`` - ``upstart``, ``systemv`` or ``systemd``
* ``$template`` -
* ``systemv`` - ``loader-functions``, ``start-debian-template``, or ``start-rpm-template``
* ``systemd`` - ``loader-functions`` or ``start-template``
* ``upstart`` - ``loader-functions`` or ``start-template``

**Syntax**

Expand Down