-
Notifications
You must be signed in to change notification settings - Fork 446
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
SystemD services now source /etc/default/{{app_name}} (resolves #737) #745
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ project/project | |
log/ | ||
target/ | ||
.cache | ||
.ensime* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# ##################################### | ||
# ##### Environment Configuration ##### | ||
# ##################################### | ||
|
||
# This file is parsed by systemd. You can modify it to specify environment | ||
# variables for your application. | ||
# | ||
# For a description of the format, see: `man systemd.exec`, section | ||
# `EnvironmentFile`. | ||
|
||
# Available replacements | ||
# ------------------------------------------------ | ||
# ${{author}} debian author | ||
# ${{descr}} debian package description | ||
# ${{exec}} startup script name | ||
# ${{chdir}} app directory | ||
# ${{retries}} retries for startup | ||
# ${{retryTimeout}} retry timeout | ||
# ${{app_name}} normalized app name | ||
# ${{daemon_user}} daemon user | ||
# ------------------------------------------------- | ||
|
||
# Setting JAVA_OPTS | ||
# ----------------- | ||
# JAVA_OPTS="-Dpidfile.path=/var/run/${{app_name}}/play.pid" | ||
|
||
# Setting PIDFILE | ||
# --------------- | ||
# PIDFILE="/var/run/${{app_name}}/play.pid" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,6 @@ object JavaServerAppPackaging extends AutoPlugin { | |
/** These settings will be provided by this archetype*/ | ||
def javaServerSettings: Seq[Setting[_]] = linuxSettings ++ debianSettings ++ rpmSettings | ||
|
||
protected def etcDefaultTemplateSource: java.net.URL = getClass.getResource(ETC_DEFAULT + "-template") | ||
|
||
/** | ||
* general settings which apply to all linux server archetypes | ||
* | ||
|
@@ -59,27 +57,30 @@ object JavaServerAppPackaging extends AutoPlugin { | |
}, | ||
// === etc config mapping === | ||
bashScriptEnvConfigLocation := Some("/etc/default/" + (packageName in Linux).value), | ||
linuxEtcDefaultTemplate <<= sourceDirectory map { dir => | ||
val overrideScript = dir / "templates" / ETC_DEFAULT | ||
if (overrideScript.exists) overrideScript.toURI.toURL | ||
else etcDefaultTemplateSource | ||
}, | ||
linuxStartScriptName := None, | ||
makeEtcDefault <<= (packageName in Linux, target in Universal, linuxEtcDefaultTemplate, linuxScriptReplacements) | ||
map makeEtcDefaultScript, | ||
linuxPackageMappings <++= (makeEtcDefault, bashScriptEnvConfigLocation) map { (conf, envLocation) => | ||
val mapping = for ( | ||
path <- envLocation; | ||
c <- conf | ||
) yield LinuxPackageMapping(Seq(c -> path), LinuxFileMetaData(Users.Root, Users.Root, "644")).withConfig() | ||
|
||
mapping.toSeq | ||
} | ||
|
||
linuxStartScriptName := None | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were redundant, right? As we only use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, they didn't work anymore in the global config scope since I added the dependency for |
||
|
||
/* etcDefaultConfig is dependent on serverLoading (systemd, systemv, etc.), | ||
* and is therefore distro specific. As such, these settings cannot be defined | ||
* in the global config scope. */ | ||
private[this] val etcDefaultConfig: Seq[Setting[_]] = Seq( | ||
linuxEtcDefaultTemplate := getEtcTemplateSource( | ||
sourceDirectory.value, | ||
serverLoading.value), | ||
makeEtcDefault := makeEtcDefaultScript( | ||
(packageName in Linux).value, | ||
(target in Universal).value, | ||
linuxEtcDefaultTemplate.value, | ||
linuxScriptReplacements.value), | ||
linuxPackageMappings ++= etcDefaultMapping( | ||
makeEtcDefault.value, | ||
bashScriptEnvConfigLocation.value) | ||
) | ||
|
||
def debianSettings: Seq[Setting[_]] = { | ||
import DebianPlugin.Names.{ Preinst, Postinst, Prerm, Postrm } | ||
inConfig(Debian)(etcDefaultConfig) ++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
inConfig(Debian)(Seq( | ||
serverLoading := Upstart, | ||
startRunlevels <<= (serverLoading) apply defaultStartRunlevels, | ||
|
@@ -131,6 +132,7 @@ object JavaServerAppPackaging extends AutoPlugin { | |
|
||
def rpmSettings: Seq[Setting[_]] = { | ||
import RpmPlugin.Names.{ Pre, Post, Preun, Postun } | ||
inConfig(Rpm)(etcDefaultConfig) ++ | ||
inConfig(Rpm)(Seq( | ||
serverLoading := SystemV, | ||
startRunlevels <<= (serverLoading) apply defaultStartRunlevels, | ||
|
@@ -242,6 +244,45 @@ object JavaServerAppPackaging extends AutoPlugin { | |
} | ||
} | ||
|
||
/* Find the template source for the given Server loading scheme, with cascading fallback | ||
* If the serverLoader scheme is SystemD, then searches for files in this order: | ||
* | ||
* (assuming sourceDirectory is `src`) | ||
* | ||
* - src/templates/etc-default-systemd | ||
* - src/templates/etc-default | ||
* - Provided template | ||
*/ | ||
|
||
private[this] def getEtcTemplateSource(sourceDirectory: File, loader: ServerLoader): java.net.URL = { | ||
val (suffix, default) = loader match { | ||
case Upstart => | ||
("-upstart", getClass.getResource(ETC_DEFAULT + "-template")) | ||
case SystemV => | ||
("-systemv", getClass.getResource(ETC_DEFAULT + "-template")) | ||
case Systemd => | ||
("-systemd", getClass.getResource(ETC_DEFAULT + "-systemd-template")) | ||
} | ||
|
||
val overrides = List[File]( | ||
sourceDirectory / "templates" / (ETC_DEFAULT + suffix), | ||
sourceDirectory / "templates" / ETC_DEFAULT) | ||
overrides. | ||
find(_.exists). | ||
map(_.toURI.toURL). | ||
getOrElse(default) | ||
} | ||
|
||
// Used to tell our packager to install our /etc/default/{{appName}} config file. | ||
protected def etcDefaultMapping(conf: Option[File], envLocation: Option[String]): Seq[LinuxPackageMapping] = { | ||
val mapping = for ( | ||
path <- envLocation; | ||
c <- conf | ||
) yield LinuxPackageMapping(Seq(c -> path), LinuxFileMetaData(Users.Root, Users.Root, "644")).withConfig() | ||
|
||
mapping.toSeq | ||
} | ||
|
||
protected def startScriptMapping(name: String, script: Option[File], loader: ServerLoader, scriptDir: String, scriptName: Option[String]): Seq[LinuxPackageMapping] = { | ||
val (path, permissions, isConf) = loader match { | ||
case Upstart => ("/etc/init/" + scriptName.getOrElse(name + ".conf"), "0644", "true") | ||
|
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 <[email protected]>" | ||
|
||
packageSummary := "Test debian package" | ||
|
||
packageDescription := """A fun package description of our software, | ||
with multiple lines.""" | ||
|
||
TaskKey[Unit]("check-etc-default") <<= (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" / "default" / "debian-test") | ||
assert(script.startsWith("# right etc-default template"), s"etc-default script wasn't picked, contents instead are:\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 @@ | ||
# right etc-default template |
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-etc-default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pure personal interest: what editor do you use with ensime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to recommend emacs + evil (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's it! Emacs and evil :)