0

I'd like to make sbt independent of my ssh session. I have installed sbt-assembly

I managed to have the it spit out a fat jar after running the tests.

[info] Assembly up to date: /home/../target/scala-2.11/root-assembly-0.1.jar
[success] Total time: 6 s, completed Aug 10, 2015 2:43:06 PM

However, I did not manage to understand what comes next. This is how my build.sbt looks like.

lazy val root = (project in file(".")).
        settings(
                organization  := "hidethis",
                version       := "0.1",
                scalaVersion  := "2.11.6",
                scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8"),
                unmanagedBase := baseDirectory.value / "custom_lib",
                mainClass in Compile := Some("webserver.Root")
        )

libraryDependencies ++= {
  val akkaV = "2.3.9"
  val sprayV = "1.3.3"
  Seq(
    "io.spray"            %%  "spray-can"     % sprayV,
    "io.spray"            %%  "spray-routing" % sprayV,
    "io.spray"            %%  "spray-json"    % "1.3.2",
    "io.spray"            %%  "spray-testkit" % sprayV  % "test",
    "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
    "com.typesafe.akka"   %%  "akka-testkit"  % akkaV   % "test",
    "org.specs2"          %%  "specs2-core"   % "2.3.11" % "test",
    "org.scalikejdbc" %% "scalikejdbc" % "2.2.7",
    "org.postgresql" % "postgresql" % "9.4-1200-jdbc41"
  )
}

Revolver.settings

There's an example in the sbt-assembly tutorial page that looks like this:

lazy val app = (project in file("app")).
  settings(commonSettings: _*).
  settings(
    // your settings here
  )

but I am not sure how this works.

Community
  • 1
  • 1
NoIdeaHowToFixThis
  • 4,484
  • 2
  • 34
  • 69
  • In the question you mentioned there was a second line of code "nohup scala ./target/scala-2.10/trafficgenerator_2.10-1.0.jar &" Isn't it what you wanted? – Tyth Aug 10 '15 at 15:05
  • I understood that `nohup` is an alternative in having `sbt-assembly` taking care of all steps. – NoIdeaHowToFixThis Aug 10 '15 at 15:27
  • 1
    No, sbt-assembly just allows you to get rid of sbt on "launch server", packing all dependencies into single jar. I guess you can just use "nohup sbt run", but never tried myself. – Tyth Aug 10 '15 at 15:29
  • `sudo nohup sbt run & exit` returns the following `[1] 14747 logout` but the server seems down – NoIdeaHowToFixThis Aug 10 '15 at 15:40

1 Answers1

1

As an alternative to nohup, you can use screen. It will create a virtual terminal that you can detach., like so:

$ echo $FOO
>
$ screen
$ FOO="bar"
$ echo $FOO
> bar

Now, you type Ctrl-a-d to detach the screen

[detached]
$ echo $FOO
>

At this point, you can terminate your session. When you ssh back into the machine, you can recover it.

$ screen -r # this recovers your screen
$ echo $FOO
bar

In your case, you would ssh to the machine, screen, then start your program either with sbt or with java my-big-jar. Once running, detach the screen and close the ssh session. The program will continue running.

Adama
  • 101
  • 10