Skip to content

Commit

Permalink
New setting daemonShell. Used in debian package to create user with
Browse files Browse the repository at this point in the history
specified shell.
FIX #235
  • Loading branch information
muuki88 committed Apr 26, 2014
1 parent a375e78 commit 64472cb
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Adding ${{user}}
if ! id -u ${{user}} > /dev/null 2>&1; then
echo "Creating user ${{user}} in group ${{group}}"
useradd --system --no-create-home --gid ${{group}} --shell /bin/false ${{user}}
useradd --system --no-create-home --gid ${{group}} --shell ${{shell}} ${{user}}
fi
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ trait JavaAppStartScriptBuilder {
appName: String,
daemonUser: String,
daemonGroup: String,
daemonShell: String,
retries: Int = 0,
retryTimeout: Int = 60): Seq[(String, String)] =
Seq(
Expand All @@ -99,7 +100,8 @@ trait JavaAppStartScriptBuilder {
"retryTimeout" -> retryTimeout.toString,
"app_name" -> appName,
"daemon_user" -> daemonUser,
"daemon_group" -> daemonGroup)
"daemon_group" -> daemonGroup,
"daemon_shell" -> daemonShell)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Keys._
import sbt._
import sbt.Keys.{ target, name, normalizedName, TaskStreams }
import linux.{ LinuxFileMetaData, LinuxPackageMapping, LinuxSymlink }
import linux.Keys.{ linuxScriptReplacements }
import linux.Keys.{ linuxScriptReplacements, daemonShell }
import com.typesafe.sbt.packager.Hashing
import com.typesafe.sbt.packager.archetypes.TemplateWriter

Expand Down Expand Up @@ -145,8 +145,8 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
chmod(cfile, "0644")
cfile
},
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, linuxScriptReplacements, linuxPackageSymlinks, target, streams)
map { (mappings, _, maintScripts, _, replacements, symlinks, t, streams) =>
debianExplodedPackage <<= (linuxPackageMappings, debianControlFile, debianMaintainerScripts, debianConffilesFile, daemonShell in Linux, linuxScriptReplacements, linuxPackageSymlinks, target, streams)
map { (mappings, _, maintScripts, _, shell, replacements, symlinks, t, streams) =>

// Create files and directories
mappings foreach {
Expand Down Expand Up @@ -191,7 +191,7 @@ trait DebianPlugin extends Plugin with linux.LinuxPlugin {
val prerm = createFileIfRequired(t / Names.Debian / Names.Prerm, LinuxFileMetaData())
val headerScript = IO.readLinesURL(DebianPlugin.headerSource)

val replacements = Seq("group" -> group, "user" -> user)
val replacements = Seq("group" -> group, "user" -> user, "shell" -> shell)

prependAndFixPerms(prerm, headerScript, LinuxFileMetaData())

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/linux/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ trait Keys {
val maintainer = SettingKey[String]("maintainer", "The name/email address of a maintainer for the native package.")
val daemonUser = SettingKey[String]("daemon-user", "User to start application daemon")
val daemonGroup = SettingKey[String]("daemon-group", "Group to start application daemon")
val daemonShell = SettingKey[String]("daemon-shell", "Shell provided for the daemon user")
val serverLoading = SettingKey[ServerLoader]("server-loader", "Loading system to be used for application start script")
val linuxPackageMappings = TaskKey[Seq[LinuxPackageMapping]]("linux-package-mappings", "File to install location mappings including owner and privileges.")
val linuxPackageSymlinks = TaskKey[Seq[LinuxSymlink]]("linux-package-symlinks", "Symlinks we should produce in the underlying package.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ trait LinuxPlugin extends Plugin {
packageDescription in Linux <<= packageDescription,
daemonUser in Linux <<= normalizedName,
daemonGroup in Linux <<= daemonUser in Linux,
daemonShell in Linux := "bin/false",
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,
maintainer in Linux, packageSummary in Linux, daemonUser in Linux, daemonGroup in Linux, daemonShell in Linux, normalizedName,
sbt.Keys.version, defaultLinuxInstallLocation)
apply { (author, descr, daemonUser, daemonGroup, name, version, installLocation) =>
apply { (author, descr, daemonUser, daemonGroup, daemonShell, name, version, installLocation) =>
val appDir = installLocation + "/" + name

// TODO Making replacements should be done somewhere else. Maybe TemplateWriter
Expand All @@ -55,7 +56,8 @@ trait LinuxPlugin extends Plugin {
chdir = appDir,
appName = name,
daemonUser = daemonUser,
daemonGroup = daemonGroup)
daemonGroup = daemonGroup,
daemonShell = daemonShell)
}

)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/typesafe/sbt/packager/rpm/RpmHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ object RpmHelper {
"--define", "_topdir " + workArea.getAbsolutePath,
"--define", "_tmppath " + tmpRpmBuildDir.getAbsolutePath
) ++ (
if (gpg) Seq("--define", "_gpg_name " + "<insert keyname>", "--sign")
else Seq.empty
) ++ Seq(spec.meta.name + ".spec")
if (gpg) Seq("--define", "_gpg_name " + "<insert keyname>", "--sign")
else Seq.empty
) ++ Seq(spec.meta.name + ".spec")
log.debug("Executing rpmbuild with: " + args.mkString(" "))
(Process(args, Some(specsDir)) ! log) match {
case 0 => ()
Expand Down
34 changes: 34 additions & 0 deletions src/sbt-test/debian/daemon-user-shell-deb/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import NativePackagerKeys._
import com.typesafe.sbt.packager.archetypes.ServerLoader

packageArchetype.java_server

serverLoading in Debian := ServerLoader.Upstart

daemonUser in Linux := "daemonuser"

daemonGroup in Linux := "daemongroup"

daemonShell in Linux := "/bin/bash"

mainClass in Compile := Some("empty")

name := "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-control-files") <<= (target, streams) map { (target, out) =>
val debian = target / "debian-test-0.1.0" / "DEBIAN"
val postinst = IO.read(debian / "postinst")
val postrm = IO.read(debian / "postrm")
assert(postinst contains "useradd --system --no-create-home --gid daemongroup --shell /bin/bash daemonuser", "postinst misses useradd for daemonuser: " + postinst)
()
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
10 changes: 10 additions & 0 deletions src/sbt-test/debian/daemon-user-shell-deb/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Run the debian packaging.
> debian:package-bin
$ exists target/debian-test-0.1.0.deb

# Check defaults
$ exists target/debian-test-0.1.0/DEBIAN/prerm
$ exists target/debian-test-0.1.0/DEBIAN/postinst

# Check files for defaults
> check-control-files

0 comments on commit 64472cb

Please sign in to comment.