Most appropriate method to persist a sbt process a

2019-02-27 15:27发布

问题:

How do I keep a process, specifically one spawned via the sbt command, alive after exiting my ssh session? The following related questions [1], [2], [3] and [4] have been informative but have not led to a definitive solution in my particular case. A brief background: I have three servers representing nodes that comprise a cluster and each node has the the same program running on it to distribute computationally intensive tasks. This process is intended to always run while the machines are up, i.e. each server is dedicate solely to this project. Each node has the following (I will update this with the correct information when I get a chance to log back in):

Ubuntu 12.04.2 LTS
JVM X.X.X (is JDK 1.7 update 24+)
Scala X.X.X
sbt X.X.X

I access each node through my university's network via ssh. I have tried tmux and detaching a session, but this only persists the process as long as my own laptop does not restart. I take the following steps to begin the program on each node:

  1. Log into each node via ssh user@host -p port
  2. Navigate to the appropriate directory and start my program with sbt *
  3. Issue the run command in the sbt console

* The actual command is sbt -Dgeotrellis cluster_seed_ip=xxx.xxx.xxx.xxx

Is disown or nohup the most appropriate approach to take? Given an answer for one or the other, what specific and syntactically correct command do I need to issue (from the sbt console if using the disown approach) so that the sbt process disassociates from my user account and will continue running after I exit the ssh session?

回答1:

It looks like SBT hanging in the background is a JLine issue. There is a workaround:

sbt -Djline.terminal=jline.UnsupportedTerminal about &

Just add this flag to any SBT command you want to run in the background.



回答2:

It is not a easy task to put sbt run as a daemon.
Most suggestions are using sbt-assembly.

If you donot want to using sbt-assembly, you may first package you scala application, then run it with scala command.

For me, the commands are, in this way, scala will continue to run after you exit ssh:

sbt clean package
nohup scala ./target/scala-2.10/trafficgenerator_2.10-1.0.jar &


回答3:

It is even more common. Try to type sbt clean & or sbt compile &. Proccess is created but it won't finish.

Solution for your question by using tmxux:

tmux new -d -s $$ && tmux send -t $$ 'SHELL_COMMAND' ENTER

In your context SHELL_COMMAND = sbt -Dgeotrellis cluster_seed_ip=xxx.xxx.xxx.xxx

You can also use tmux behind byobu:

byobu new -d -s $$ && tmux send -t $$ 'SHELL_COMMAND' ENTER

After that if you type byobu then you enter session of your command.