From 141c075b0d06477344f41f9fe9b423892664121c Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Sat, 13 Dec 2014 13:56:56 +0100 Subject: [PATCH 1/2] FIX #435 Adding loader and control functions --- .../archetypes/java_server/rpm/postinst-template | 4 ---- .../archetypes/java_server/rpm/postun-template | 2 ++ .../archetypes/java_server/rpm/preinst-template | 15 +++++---------- .../archetypes/java_server/rpm/preun-template | 2 ++ 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postinst-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postinst-template index 2cb93e25a..a5c6eb46f 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postinst-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postinst-template @@ -1,7 +1,3 @@ ${{loader-functions}} -${{control-functions}} - -addGroup ${{daemon_group}} -addUser ${{daemon_user}} ${{daemon_group}} "${{app_name}} user-daemon" "${{daemon_shell}}" startService ${{app_name}} || echo "${{app_name}} could not be registered or started" diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postun-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postun-template index df7626144..7413264b7 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postun-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/postun-template @@ -1,3 +1,5 @@ +${{control-functions}} + # Removing system user/group : ${{daemon_user}} and ${{daemon_group}} # Scriptlet syntax: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Syntax diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preinst-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preinst-template index 411de8fbe..87d9e99c6 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preinst-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preinst-template @@ -1,11 +1,6 @@ +${{control-functions}} + # Adding system user/group : ${{daemon_user}} and ${{daemon_group}} -if ! getent group | grep -q "^${{daemon_group}}:" ; -then - echo "Creating system group: ${{daemon_group}}" - groupadd --system ${{daemon_group}} -fi -if ! getent passwd | grep -q "^${{daemon_user}}:"; -then - echo "Creating system user: ${{daemon_user}}" - useradd --gid ${{daemon_group}} --no-create-home --system -c '${{app_name}} daemon-user' ${{daemon_user}} -fi + +addGroup ${{daemon_group}} +addUser ${{daemon_user}} ${{daemon_group}} "${{app_name}} user-daemon" "${{daemon_shell}}" \ No newline at end of file diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preun-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preun-template index ef97b2642..a80aa144f 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preun-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/java_server/rpm/preun-template @@ -1,3 +1,5 @@ +${{loader-functions}} + # Halting ${{app_name}} echo "Shutdown ${{app_name}}" service ${{app_name}} stop || echo "Could not stop ${{app_name}}" From 610fa1cee076bd72c79d2852dddc75d235bf4306 Mon Sep 17 00:00:00 2001 From: Nepomuk Seiler Date: Sat, 13 Dec 2014 14:51:04 +0100 Subject: [PATCH 2/2] Building a test app --- test-project-simple/build.sbt | 2 +- .../src/main/scala/ExampleApp.scala | 16 +++++++++++++++- test-project-simple/src/templates/etc-default | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test-project-simple/src/templates/etc-default diff --git a/test-project-simple/build.sbt b/test-project-simple/build.sbt index 85b2a6b06..1c6429a13 100644 --- a/test-project-simple/build.sbt +++ b/test-project-simple/build.sbt @@ -6,7 +6,7 @@ libraryDependencies ++= Seq( mainClass in Compile := Some("ExampleApp") -enablePlugins(JavaAppPackaging, JDebPackaging) +enablePlugins(JavaServerAppPackaging, JDebPackaging) maintainer := "Josh Suereth " packageSummary := "Minimal Native Packager" diff --git a/test-project-simple/src/main/scala/ExampleApp.scala b/test-project-simple/src/main/scala/ExampleApp.scala index 66a697b6e..afb108019 100644 --- a/test-project-simple/src/main/scala/ExampleApp.scala +++ b/test-project-simple/src/main/scala/ExampleApp.scala @@ -1,4 +1,18 @@ +import java.util.concurrent._ + object ExampleApp extends App { - println("Hello, world!") + val executorService = Executors newFixedThreadPool 2 + + while (true) { + for(i <- 0 to 5) executorService execute HelloWorld(i) + Thread sleep 5000 + } + } + +case class HelloWorld(i: Int) extends Runnable { + def run() { + println(s"[$i] Hello, world!") + } +} \ No newline at end of file diff --git a/test-project-simple/src/templates/etc-default b/test-project-simple/src/templates/etc-default new file mode 100644 index 000000000..cd0cd6a69 --- /dev/null +++ b/test-project-simple/src/templates/etc-default @@ -0,0 +1,2 @@ +-J-Xms64m +-J-Xmx128m \ No newline at end of file