java 如何在后台运行 Solr Jetty

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4287561/
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-30 05:42:28  来源:igfitidea点击:

How to run Solr Jetty in background

javasolrterminaljetty

提问by user103219

I am using the Jetty/Solr build that comes with Solr and would like to run it in the background instead of in the terminal.

我正在使用 Solr 附带的 Jetty/Solr 构建,并希望在后台而不是在终端中运行它。

Right now I start it by java -jar start.jarbut I would like it to log to a file and run in the background on the server so that I can close the terminal window.

现在我开始它,java -jar start.jar但我希望它登录到一个文件并在服务器的后台运行,以便我可以关闭终端窗口。

I'm sure there is some java config that I can't find.

我确定有一些我找不到的 java 配置。

I have tried java -jar start.jar > log.txt &but no luck still outputs to the terminal window.

我已经尝试过,java -jar start.jar > log.txt &但仍然没有运气输出到终端窗口。

Thanks.

谢谢。

回答by Joel

Try something like:

尝试类似:

nohup yourcommand > output.log 2>&1 &

nohupwill prevent yourcommand from being terminated in the event you log out.

nohup将防止您的命令在您注销时被终止。

&will run it in the background.

&将在后台运行它。

> output.logwill send stdout to output.log

> output.log将标准输出发送到 output.log

2>&1will redirect stderr to stdout

2>&1将 stderr 重定向到 stdout

回答by zinan.yumak

nohup is used to execute commands that runs after logout from a shell. What you need here is '2>&1'. This redirects standart error to the standart output. So everything will be logged to log.txt. Try this

nohup 用于执行从 shell 注销后运行的命令。这里你需要的是'2>&1'。这会将标准错误重定向到标准输出。所以一切都将被记录到 log.txt。试试这个

java -jar start.jar > log.txt 2>&1

java -jar start.jar > log.txt 2>&1

Also you can add an '&' start it as a background process.

您也可以添加一个“&”作为后台进程启动它。

回答by Shashikant Kore

You can run it with screenif you are on unix.

screen如果你在 unix 上,你可以运行它。

回答by spydon

You can properly install it as a linux service too.

您也可以将其正确安装为 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 (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 now 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
# ========================

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 reboot, 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. You could also consider doing a symlink to the jetty.sh so it will be easier to upgrade.

这应该适用于大多数现代发行版,但我只在基于 debian 的发行版上尝试过。你也可以考虑对 jetty.sh 做一个符号链接,这样升级会更容易。

回答by Camilo Díaz Repka

You may want to try nohup, as explained in this previous answer.

您可能想尝试nohup,如上一个答案中所述