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

generating etc default, different postinst script for sysvinit #93

Merged
merged 2 commits into from
Dec 2, 2013
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
@@ -0,0 +1,4 @@
#Some start script options could be overridden here
#RUN_OPTS=""
#DAEMON_USER=""
#JAVA_CMD=""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service ${{app_name}} start || echo "${{app_name}} could not be started. Try manually with service ${{app_name}} start"
Copy link
Member

Choose a reason for hiding this comment

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

I think the other postinst also does user/group additions. Do you want that in here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

At DebianPlugin.scala:159

IO.append(postinst, TemplateWriter.generateScript(DebianPlugin.postinstGroupaddTemplateSource, replacements))

I think this should append users and groups additions in any postinst. But I also think that this operations should be prepended.

Copy link
Member

Choose a reason for hiding this comment

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

Right, prepending sort of makes sense. What makes better sense is to somehow document that users can either specify where this gets injected in a script (via some comment/flag) OR we prepend.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ get_java_cmd() {
if [ -x "$JAVA_HOME/bin/java" ]; then
echo "$JAVA_HOME/bin/java"
else
echo `which java`
echo $(which java)
fi
}

Expand All @@ -37,7 +37,7 @@ RUN_CMD="-cp ${{app_classpath}} ${{app_main_class}} $RUN_OPTS"

start_daemon() {
log_daemon_msg "Starting ${{app_name}}"
start-stop-daemon --background --start --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD
start-stop-daemon --background --chuid "$DAEMON_USER" --make-pidfile --pidfile "$PIDFILE" --exec "$JAVA_CMD" --start -- $RUN_CMD
}


Expand All @@ -50,7 +50,6 @@ stop_daemon() {
exit 2
}


case "$1" in

start)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ object JavaAppStartScript {

protected def upstartTemplateSource: java.net.URL = getClass.getResource("upstart-template")
protected def sysvinitTemplateSource: java.net.URL = getClass.getResource("sysvinit-template")

protected def postinstTemplateSource: java.net.URL = getClass.getResource("postinst-template")
protected def postinstSysvinitTemplateSource: java.net.URL = getClass.getResource("postinst-sysvinit-template")
protected def preremTemplateSource: java.net.URL = getClass.getResource("prerem-template")


Expand All @@ -28,8 +28,13 @@ object JavaAppStartScript {
TemplateWriter.generateScript(preremTemplateSource, Seq("app_name" -> appName))


def generatePostinst(appName: String): String =
TemplateWriter.generateScript(postinstTemplateSource, Seq("app_name" -> appName))
def generatePostinst(appName: String, loader: ServerLoader): String =
loader match {
case Upstart =>
TemplateWriter.generateScript(postinstTemplateSource, Seq("app_name" -> appName))
case SystemV =>
TemplateWriter.generateScript(postinstSysvinitTemplateSource, Seq("app_name" -> appName))
}


/**
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, mainClass, normalizedName }
import SbtNativePackager._
import com.typesafe.sbt.packager.linux.LinuxPackageMapping
import com.typesafe.sbt.packager.linux.{LinuxFileMetaData, LinuxPackageMapping}

/**
* This class contains the default settings for creating and deploying an archetypical Java application.
Expand All @@ -21,6 +21,7 @@ object JavaServerAppPackaging {
import ServerLoader._

def settings: Seq[Setting[_]] = JavaAppPackaging.settings ++ debianSettings
protected def etcDefaultTemplateSource: java.net.URL = getClass.getResource("etc-default-template")

def debianSettings: Seq[Setting[_]] =
Seq(
Expand All @@ -46,6 +47,11 @@ object JavaServerAppPackaging {
},
debianMakeStartScript <<= (debianStartScriptReplacements, normalizedName, target in Universal, serverLoading in Debian)
map makeDebianStartScript,
debianMakeEtcDefault <<= (normalizedName, target in Universal, serverLoading in Debian)
map makeEtcDefaultScript,
linuxPackageMappings in Debian <++= (debianMakeEtcDefault, normalizedName) map {(conf, name) =>
conf.map(c => LinuxPackageMapping(Seq(c -> s"/etc/default/$name")).withConfig()).toSeq
},
linuxPackageMappings in Debian <++= (debianMakeStartScript, normalizedName, serverLoading in Debian)
map { (script, name, loader) =>
val (path, permissions) = loader match {
Expand All @@ -59,7 +65,7 @@ object JavaServerAppPackaging {
},
// TODO - only make these if the upstart config exists...
debianMakePrermScript <<= (normalizedName, target in Universal) map makeDebianPrermScript,
debianMakePostinstScript <<= (normalizedName, target in Universal) map makeDebianPostinstScript)
debianMakePostinstScript <<= (normalizedName, target in Universal, serverLoading in Debian) map makeDebianPostinstScript)


private def makeDebianStartScript(
Expand All @@ -81,10 +87,22 @@ object JavaServerAppPackaging {
}


protected def makeDebianPostinstScript(name: String, tmpDir: File): Option[File] = {
val scriptBits = JavaAppStartScript.generatePostinst(name)
protected def makeDebianPostinstScript(name: String, tmpDir: File, loader: ServerLoader): Option[File] = {
val scriptBits = JavaAppStartScript.generatePostinst(name, loader)
val script = tmpDir / "tmp" / "bin" / "debian-postinst"
IO.write(script, scriptBits)
Some(script)
}

protected def makeEtcDefaultScript(name: String, tmpDir: File, loader: ServerLoader): Option[File] = {
loader match {
case Upstart => None
case SystemV => {
val scriptBits = TemplateWriter.generateScript(etcDefaultTemplateSource, Seq.empty)
val script = tmpDir / "tmp" / "bin" / "etc-default"
IO.write(script, scriptBits)
Some(script)
}
}
}
}
1 change: 1 addition & 0 deletions src/main/scala/com/typesafe/sbt/packager/debian/Keys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ trait DebianKeys {
| appMainClass - main class to start
| daemonUser - daemon user
""".stripMargin)
val debianMakeEtcDefault = TaskKey[Option[File]]("makeEtcDefault", "Creates or discovers the /etc/default/ script")
}


Expand Down