Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

linux - How to run sbt as daemon?

I've tried nohup "sbt run" &

returns : nohup: failed to run command ‘sbt run’: No such file or directory

and tried :

nohup sbt run &
[2] 7897
# nohup: ignoring input and appending output to ‘nohup.out’

When I carriage return expecting process to continue running I receive :

[2]+  Stopped                 nohup sbt run

How to run sbt as a daemon ?

Update :

sbt run </dev/null &
[5] 8961

I think cd up one dir :

# cd ..

[5]+  Stopped                 sbt run < /dev/null  (wd: /home/sum)
(wd now: /home)

So it starts as daemon but if I perform any actions such as changing dir it kills the process ? How to keep process running ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Looks like sbt requested input from your terminal. If it does not really need input (which is probably the case when you run program in background), you can run it like this:

sbt run </dev/null >output-file &

See this answer for details.

EDIT

Ok, now that was a puzzle. Short answer: run sbt as follows:

setsid nohup sbt run &

Rationale:

The reason why sbt stops is arrival of SIGTTOU signal. It is delivered to background process in several cases, which include modifying terminal configuration. This is our case because according to strace -f sbt run &, sbt does a lot of black magic under the hood like this:

[pid 16600] execve("/usr/bin/sh", ["sh", "-c", "stty -g < /dev/tty"], [/* 75 vars */] <unfinished ...>

To work this around, you can run sbt in a different session to detach it from current terminal, so that it won't open /dev/tty and mess with our terminal.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...