简体   繁体   English

如何正确启动Jetty

[英]How To Start Jetty Properly

this really silly question probably, as no one else seems to be having this problem. 这可能是一个非常愚蠢的问题,因为似乎没有人有这个问题。 In the Jetty documentation it says jar -jar start.jar starts Jetty, and it does. 在Jetty文档中,它说jar -jar start.jar启动Jetty,它确实如此。 But when I close my SSH console, obviously it dies. 但是当我关闭我的SSH控制台时,显然它已经死了。

How do I run it PROPERLY? 我该如何正确运行?

Is this for running on a production machine that will actually serve up an application running under Jetty? 这是否可以在生产机器上运行,该生产机器实际上将在Jetty下运行应用程序? I assume this is the case, since you're asking about starting it properly . 我认为情况就是这样,因为你要求正确启动它。

If so, you need a proper process supervision system, such as runit , daemontools , monit , upstart , systemd , or good ol' SysV init.d (as mentioned w/ a gist ). 如果是这样,你需要一个适当的工艺监督体系,如runitdaemontools的monit的暴发户systemd ,或好醇” 的SysV init.d中 (如提及W / 梗概 )。 Which to use depends on your preferences, business needs, and often, your underlying operating system. 使用哪种方法取决于您的偏好,业务需求以及您的底层操作系统。

I use and prefer runit . 我使用并喜欢runit It is built on solid principles (daemontools), and for my preferred distribution (Debian and Ubuntu) it is nicely packaged by the author himself. 它建立在坚实的原则 (daemontools) 之上 ,对于我喜欢的发行版(Debian和Ubuntu),它由作者自己很好地 打包

Despite being recommended in other answers, and mentioned in comments, starting a long running process in screen/tmux, or via nohup is sub-optimal. 尽管在其他答案中被推荐,并在评论中提到,在screen / tmux中开始长时间运行的过程,或者通过nohup是次优的。 You don't have any real control over the process. 您无法真正控制该过程。 It won't be restarted if it dies. 如果它死了它将不会重新启动。 You have to manually find its PID and otherwise manually manage the service. 您必须手动查找其PID,否则手动管理服务。 You have to do more manual work to get the log output (redirection, sending to some random file, etc). 你必须做更多的手工工作来获取日志输出(重定向,发送到一些随机文件等)。 You cannot reliably make it depend on other processes, or have other processes depend on it. 您不能可靠地使其依赖于其他进程,或者让其他进程依赖于它。 Decent process supervision systems provide all this functionality for you by default. 体面的过程监控系统默认为您提供所有这些功能。

If your goal is something else entirely, then please update the question to be more specific about your use case. 如果您的目标完全不同,那么请更新问题以更具体地说明您的用例。

java -jar start.jar & 

(to run in the background) should also work, though logging won't be transmuted as nice as w/nohup. (在后台运行)也应该可以工作,虽然日志记录不会像w / nohup一样好转。

This is because killing the shell that started a process (eg by logging out) will kill process to unless they're background processes. 这是因为杀死启动进程的shell(例如通过注销)会杀死进程,除非它们是后台进程。 Screen works since as well since it runs in the background, and screen effectively keeps your session running while you attach/detach. 屏幕也起作用,因为它在后台运行,并且屏幕有效地保持会话在您附加/分离时运行。

If you're on a *nix system, the best solution is may be using a script in /etc/init.d (or whatever your system's equivalent is). 如果您使用的是* nix系统,最好的解决方案可能是使用/etc/init.d的脚本(或者系统的等效系统)。 There's one at https://gist.github.com/404672 . 有一个在https://gist.github.com/404672

Otherwise, using nohup or screen from the command-line will at least have the process not die when you log out. 否则,从命令行使用nohupscreen将至少让您在注销时不会死亡。 So will putting the process in the background with & . 因此,将使用&将过程置于后台。

One way is to use nohup 一种方法是使用nohup

nohup java -jar start.jar

This has the advantage of writing stdout and stderr to a file 这具有将stdout和stderr写入文件的优点

Another way would be to use screen 另一种方法是使用screen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM