-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added simple upstart script - Added Keys - Added Tasks - Incremented sbt version to 0.13.0 for testing (maybe reverted in next commits) Moving upstart script to DebianPlugin and adding TaskKeys #42
- Loading branch information
Showing
6 changed files
with
281 additions
and
162 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/main/resources/com/typesafe/sbt/packager/archetypes/upstart-template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# generated upstart config | ||
|
||
description "${{descr}}" | ||
author "${{author}}" | ||
|
||
# Stanzas | ||
# | ||
# Stanzas control when and how a process is started and stopped | ||
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn | ||
|
||
# When to start the service | ||
start on runlevel [2345] | ||
|
||
# Automatically restart process if crashed. Tries ${{retries}} times every ${{retryTimeout}} seconds | ||
respawn | ||
respawn limit ${{retries}} ${{retryTimeout}} | ||
|
||
# set the working directory of the job processes | ||
chdir ${{chdir}} | ||
|
||
# Start the process | ||
exec ${{exec}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/scala/com/typesafe/sbt/packager/archetypes/JavaAppUpstartScript.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.typesafe.sbt.packager.archetypes | ||
|
||
/** | ||
* Constructs an upstart script for running a java application. | ||
* | ||
* Makes use of the associated upstart-template, with a few hooks | ||
* | ||
*/ | ||
object JavaAppUpstartScript { | ||
|
||
private[this] def upstartTemplateSource = getClass.getResource("upstart-template") | ||
private[this] def charset = java.nio.charset.Charset.forName("UTF-8") | ||
|
||
/** | ||
* | ||
* @param author - | ||
* @param description - short description | ||
* @param execScript - name of the script in /usr/bin | ||
* @param chdir - execution path of the script | ||
* @param retries - on fail, how often should a restart be tried | ||
* @param retryTimeout - pause between retries | ||
* @return Seq of key,replacement pairs | ||
*/ | ||
def makeReplacements( | ||
author: String, | ||
descr: String, | ||
execScript: String, | ||
chdir: String, | ||
retries: Int = 0, | ||
retryTimeout: Int = 60): Seq[(String, String)] = Seq( | ||
"exec" -> execScript, | ||
"author" -> author, | ||
"descr" -> descr, | ||
"chdir" -> chdir, | ||
"retries" -> retries.toString, | ||
"retryTimeout" -> retryTimeout.toString) | ||
|
||
private def replace(line: String, replacements: Seq[(String, String)]): String = { | ||
replacements.foldLeft(line) { | ||
case (line, (key, value)) => | ||
("\\$\\{\\{" + key + "\\}\\}").r.replaceAllIn(line, java.util.regex.Matcher.quoteReplacement(value)) | ||
} | ||
} | ||
|
||
def generateScript(replacements: Seq[(String, String)]): String = { | ||
val sb = new StringBuilder | ||
for (line <- sbt.IO.readLinesURL(upstartTemplateSource, charset)) { | ||
sb append replace(line, replacements) | ||
sb append "\n" | ||
} | ||
sb toString | ||
} | ||
|
||
} |
Oops, something went wrong.