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

编程入门 行业动态 更新时间:2024-10-06 16:28:11
本文介绍了如何将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作为守护程序运行?

本文发布于:2023-11-23 22:03:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   程序   sbt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!