[英]How to run Solr Jetty in background
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.jar
but 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. 谢谢。
Try something like: 尝试类似的东西:
nohup yourcommand > output.log 2>&1 &
nohup will prevent yourcommand from being terminated in the event you log out. nohup将阻止您在注销时终止您的命令。
& will run it in the background. &将在后台运行它。
> output.log will send stdout to output.log > output.log会将stdout发送到output.log
nohup is used to execute commands that runs after logout from a shell. nohup用于执行从shell注销后运行的命令。 What you need here is '2>&1'.
你需要的是'2>&1'。 This redirects standart error to the standart output.
这会将标准错误重定向到标准输出。 So everything will be logged to log.txt.
所以一切都会记录到log.txt。 Try this
尝试这个
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. 您还可以添加'&'作为后台进程启动它。
You can properly install it as a linux service too. 您也可以将其正确安装为Linux服务。
cd to your jetty folder, for example mine is: cd到您的jetty文件夹,例如我的是:
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. 这适用于大多数现代发行版,但我只在基于debian的发行版上尝试过。 You could also consider doing a symlink to the jetty.sh so it will be easier to upgrade.
您还可以考虑对jetty.sh进行符号链接,以便更容易升级。
如果你在unix screen
你可以用screen
运行它。
您可能想尝试nohup
,如前面的答案所述 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.