如何将sbt作为守护程序运行? [英] How to run sbt as daemon?

查看:93
本文介绍了如何将sbt作为守护程序运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了nohup "sbt run" &

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

并尝试:

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

如何将sbt作为守护程序运行?

How to run sbt as a daemon ?

更新:

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

我认为cd指向一个目录:

I think cd up one dir :

# cd ..

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

所以它作为守护程序启动,但是如果我执行任何操作(例如更改dir),它将终止该进程?如何保持进程运行?

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

推荐答案

看起来像sbt从您的终端请求的输入.如果确实不需要输入(可能是在后台运行程序),则可以这样运行:

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.

编辑

好吧,现在这是一个难题.简短的答案:按以下方式运行sbt:

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

setsid nohup sbt run &

理论上:

sbt停止的原因是SIGTTOU信号的到达.在几种情况下,它会交付给后台进程,其中包括修改终端配置.这是我们的情况,因为根据strace -f sbt run &sbt在引擎盖下做了很多黑魔法,如下所示:

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 ...>

要解决此问题,您可以在不同的会话中运行sbt,以将其与当前终端分离,这样它就不会打开/dev/tty并弄乱我们的终端.

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.

这篇关于如何将sbt作为守护程序运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆