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

Unify linux script replacements #182 #192

Merged
merged 2 commits into from
Mar 12, 2014
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 @@ -61,11 +61,6 @@ trait GenericPackageSettings

def mapGenericFilesToLinux: Seq[Setting[_]] = Seq(

// Default place to install code.
defaultLinuxInstallLocation := "/usr/share",
defaultLinuxLogsLocation := "/var/log",
defaultLinuxConfigLocation := "/etc",

// First we look at the src/linux files
linuxPackageMappings <++= (sourceDirectory in Linux) map { dir =>
mapGenericMappingsToLinux(MappingsHelper contentOf dir, Users.Root, Users.Root)(identity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ trait JavaAppStartScriptBuilder {
}

/**
* TODO move this to TemplateWriter or case class
*
* @param author -
* @param description - short description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ object JavaServerAppPackaging {
* - config directory
*/
def linuxSettings: Seq[Setting[_]] = Seq(
// This one is begging for sbt 0.13 syntax...
linuxScriptReplacements <<= (
// TODO do we need to separated rpm and debian maintainers?
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, normalizedName,
sbt.Keys.version, defaultLinuxInstallLocation, linuxJavaAppStartScriptBuilder in Debian)
apply { (author, descr, daemonUser, daemonGroup, name, version, installLocation, builder) =>
val appDir = installLocation + "/" + name

builder.makeReplacements(
author = author,
description = descr,
execScript = name,
chdir = appDir,
appName = name,
daemonUser = daemonUser,
daemonGroup = daemonGroup)
},
// === logging directory mapping ===
linuxPackageMappings <+= (normalizedName, defaultLinuxLogsLocation, daemonUser in Linux, daemonGroup in Linux) map {
(name, logsDir, user, group) => packageTemplateMapping(logsDir + "/" + name)() withUser user withGroup group withPerms "755"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ package debian
import Keys._
import sbt._
import sbt.Keys.{ target, name, normalizedName, TaskStreams }
import linux.LinuxPackageMapping
import linux.LinuxFileMetaData
import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink }
import linux.Keys.{ linuxScriptReplacements }
import com.typesafe.sbt.packager.Hashing
import com.typesafe.sbt.packager.linux.LinuxSymlink
import com.typesafe.sbt.packager.archetypes.TemplateWriter

trait DebianPlugin extends Plugin with linux.LinuxPlugin {
Expand All @@ -33,8 +32,8 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
// TODO - Can we do anything about user/group ownership?
}

private[this] def filterAndFixPerms(script: File, replacements: DebianControlScriptReplacements, perms: LinuxFileMetaData): File = {
val filtered = TemplateWriter.generateScript(script.toURI.toURL, replacements.makeReplacements)
private[this] def filterAndFixPerms(script: File, replacements: Seq[(String, String)], perms: LinuxFileMetaData): File = {
val filtered = TemplateWriter.generateScript(script.toURI.toURL, replacements)
IO.delete(script)
IO.write(script, filtered)
chmod(script, perms.permissions)
Expand Down Expand Up @@ -95,9 +94,6 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
packageSummary in Debian <<= packageSummary in Linux,
maintainer in Debian <<= maintainer in Linux,

// Debian Control Scripts
debianControlScriptsReplacements <<= (maintainer in Debian, packageSummary in Debian, normalizedName, version) apply DebianControlScriptReplacements,

debianControlScriptsDirectory <<= (sourceDirectory) apply (_ / "debian" / Names.Debian),
debianMaintainerScripts := Seq.empty,
debianMakePreinstScript := None,
Expand Down Expand Up @@ -149,7 +145,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
chmod(cfile, "0644")
cfile
},
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, debianControlScriptsReplacements, linuxPackageSymlinks, target, streams)
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, linuxScriptReplacements, linuxPackageSymlinks, target, streams)
map { (mappings, _, maintScripts, _, replacements, symlinks, t, streams) =>

// Create files and directories
Expand Down
25 changes: 0 additions & 25 deletions src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,6 @@ trait DebianKeys {
val debianMakePostinstScript = TaskKey[Option[File]]("makePostInstScript", "Creates or discovers the postinst script used by this project")
val debianMakePostrmScript = TaskKey[Option[File]]("makePostrmScript", "Creates or discovers the postrm script used by this project")

// Debian upstart scripts
val debianControlScriptsReplacements = SettingKey[DebianControlScriptReplacements]("debianControlScriptsReplacements",
"""|Replacements of template parameters used in the upstart script.
| Default supported templates:
| author - author of this project
| descr - description
| name - normalized name of the app
| version - app version
""".stripMargin)

@deprecated("use linuxScriptReplacements", "0.7.0")
val debianScriptReplacements = TaskKey[Seq[(String, String)]]("upstartScriptReplacements",
"""|Replacements of template parameters used in the upstart script.
| Default supported templates:
| execScript - name of the script in /usr/bin
| author - author of this project
| descr - short description
| chdir - execution path of the script
| retries - on fail, how often should a restart be tried
| retryTimeout - pause between retries
| appName - name of application
| appClasspath - application classpath
| appMainClass - main class to start
| daemonUser - daemon user
""".stripMargin)
}

/** Keys used for Debian specific settings. */
Expand Down
31 changes: 30 additions & 1 deletion src/main/scala/com/typesafe/sbt/packager/linux/LinuxPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ package linux
import Keys._
import sbt._
import sbt.Keys.{ normalizedName }
import packager.Keys.{
defaultLinuxInstallLocation,
defaultLinuxConfigLocation,
defaultLinuxLogsLocation
}
import com.typesafe.sbt.packager.linux.LinuxPlugin.Users
import com.typesafe.sbt.packager.archetypes.JavaAppStartScript

/**
* Plugin trait containing all the generic values used for
Expand All @@ -29,7 +35,30 @@ trait LinuxPlugin extends Plugin {
packageSummary in Linux <<= packageSummary,
packageDescription in Linux <<= packageDescription,
daemonUser in Linux <<= normalizedName,
daemonGroup <<= daemonUser in Linux)
daemonGroup <<= daemonUser in Linux,
defaultLinuxInstallLocation := "/usr/share",
defaultLinuxLogsLocation := "/var/log",
defaultLinuxConfigLocation := "/etc",

// This one is begging for sbt 0.13 syntax...
linuxScriptReplacements <<= (
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, normalizedName,
sbt.Keys.version, defaultLinuxInstallLocation)
apply { (author, descr, daemonUser, daemonGroup, name, version, installLocation) =>
val appDir = installLocation + "/" + name

// TODO Making replacements should be done somewhere else. Maybe TemplateWriter
JavaAppStartScript.Debian.makeReplacements(
author = author,
description = descr,
execScript = name,
chdir = appDir,
appName = name,
daemonUser = daemonUser,
daemonGroup = daemonGroup)
}

)

/** DSL for packaging files into .deb */
def packageMapping(files: (File, String)*) = LinuxPackageMapping(files)
Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/debian/override-control-files/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ TaskKey[Unit]("check-control-files") <<= (target, streams) map { (target, out) =
val postrm = IO.read(debian / "postrm")
val prerm = IO.read(debian / "prerm")
// This is a fragile test
assert(postinst equals "echo 'custom postinst'\n", "Wrong postinst:\n" + postinst)
// echo 'custom postinst ${{app_name}} ${{chdir}} ${{daemonUser}} ${{daemonGroup}}'
assert(postinst equals "echo 'custom postinst debian-test /usr/share/debian-test root root'\n", "Wrong postinst:\n" + postinst)
assert(preinst equals "echo 'custom preinst'\n", "Wrong preinst:\n" + preinst)
assert(postrm equals "echo 'custom postrm'\n", "Wrong postrm:\n" + postrm)
assert(prerm equals "echo 'custom prerm'\n", "Wrong prerm:\n" + prerm)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
echo 'custom postinst'
echo 'custom postinst ${{app_name}} ${{chdir}} ${{daemon_user}} ${{daemon_group}}'