macos 关闭终端窗口后,Jetty 服务器停止运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5173776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:46:50  来源:igfitidea点击:

Jetty server stops running after closing terminal window

javamacosjetty

提问by einstein

I am a newbie when it comes to Java and Jetty app deployment. I use the default settings for setting up my jetty serve and ran java -jar start.jaron my terminal window. The server runs as expected, but when I close my terminal it stops. Is this normal? I used XAMPP before and there you can close the terminal without any problem. How do I overcome this problem, everybody needs to shut down there personal computer once in a while.

我是 Java 和 Jetty 应用程序部署的新手。我使用默认设置来设置我的码头服务并java -jar start.jar在我的终端窗口上运行。服务器按预期运行,但是当我关闭终端时它停止了。这是正常的吗?我之前使用过 XAMPP,在那里您可以毫无问题地关闭终端。我如何克服这个问题,每个人都需要偶尔关闭个人电脑。

I'm using a mac btw.

顺便说一句,我正在使用 mac。

回答by Matthew Gilliard

It sounds like you're using ssh or something like that to start Jetty on a remote Linux/Unix server.

听起来您正在使用 ssh 或类似方法在远程 Linux/Unix 服务器上启动 Jetty。

So, you can use nohup java -jar start.jar &- nohupwill prevent your process from being stopped by the usual Unix "hangup" signal (ref) when you log out, and the &will put jetty as a background process so you can type exitor whatever to log out.

因此,您可以使用nohup java -jar start.jar &-nohup将防止您的进程在您注销时被通常的 Unix“挂断”信号(ref)停止,并且&将码头作为后台进程,以便您可以键入exit或注销。

If you want to be able to re-attach to the Jetty terminal, I'd recommend reading up on GNU screen.

如果您希望能够重新连接到 Jetty 终端,我建议您阅读GNU screen

If you want to stop jetty gracefully again, I'd really recommend using it as a service, or using screento avoid losing the terminal. But if it's too late for that you can find the PID in the output of jps -land then call kill $PID.

如果您想再次优雅地停止码头,我真的建议将其用作服务,或者使用screen以避免丢失终端。但是,如果为时已晚,您可以在 的输出中找到 PID jps -l,然后调用kill $PID.

回答by Dmytro

try "nohup java -jar start.jar &"

尝试“nohup java -jar start.jar &”

and i'm already say it in previous question )

我已经在上一个问题中说过了)

回答by Dmytro

How to kill process:

如何杀死进程:

1) java style

1)Java风格

when start jetty :

启动码头时:

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar

for stop:

停止:

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar -stop

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar -stop

P.S. ports can be any - but they must be the same for start and kill commands :)

PS 端口可以是任何 - 但它们对于启动和终止命令必须相同:)

2) linux style

2)Linux风格

kill process by PID

通过PID杀死进程

回答by spydon

You can properly install it as a linux service(if you are actually connecting to a linux server) too.

您也可以将其正确安装为 linux 服务(如果您实际上是连接到 linux 服务器)。

cd to your jetty folder, for example mine is:

cd 到您的码头文件夹,例如我的是:

cd /home/spydon/jetty/

They have actually made most of the work with the jetty.sh file, so copy that one to /etc/init.d/

他们实际上已经使用 jetty.sh 文件完成了大部分工作,因此将其复制到 /etc/init.d/

sudo cp ./bin/jetty.sh /etc/init.d/jetty

Then open the file with your favorite text editor, like vim or nano

然后用你最喜欢的文本编辑器打开文件,比如 vim 或 nano

sudo vim /etc/init.d/jetty

In the beginning simply uncomment(simply remove the hash(#)) three lines that says something like

一开始简单地取消注释(简单地删除哈希(#))三行,上面写着类似的东西

 #chkconfig: 3 99 99
 #description: Jetty 9 webserver
 #processname: jetty

Meanwhile you have the text editor open, also add the jetty home directory to the beginning of the file, mine looks like this:

同时打开文本编辑器,将 jetty 主目录添加到文件的开头,我的看起来像这样:

#!/usr/bin/env bash  
#
# Startup script for jetty under *nix systems (it works under NT/cygwin too).
JETTY_HOME=/home/spydon/jetty

# To get the service to restart correctly on reboot, uncomment below (3 lines):
# ========================
 chkconfig: 3 99 99
 description: Jetty 9 webserver
 processname: jetty
# ========================

(You don't actually need to uncomment those three lines for it to work, only add the jetty_home. But for a proper deploy you should probably fix those lines.)

(您实际上不需要取消注释这三行即可使其工作,只需添加 jetty_home。但为了正确部署,您可能应该修复这些行。)

Now you should be able to start it with

现在你应该可以开始了

sudo /etc/init.d/jetty start

And if you want it to run every time you boot, simply add

如果您希望它每次启动时都运行,只需添加

sudo ln -s /etc/init.d/jetty /etc/rc1.d/K99jetty
sudo ln -s /etc/init.d/jetty /etc/rc2.d/S99jetty

This should work for most modern distros, but I've only tried it on debian based ones.

这应该适用于大多数现代发行版,但我只在基于 debian 的发行版上尝试过。

回答by limc

You can set up jetty to run as a service... here's the instruction for linuxand windows. This way, you don't need to worry about launching jetty everytime through the terminal.

您可以将 jetty 设置为作为服务运行...这里是linuxwindows的说明。这样,您就不必担心每次通过终端启动 jetty。