开发者

How To Start Jetty Properly

开发者 https://www.devze.com 2023-01-08 16:57 出处:网络
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. But when I close my

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. But when I close my SSH console, obviously it dies.

How do I run it PROPERLY?


Is this for running on a production machine that will actually serve up an application running under 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). Which to use depends on your preferences, business needs, and often, your underlying operating system.

I use and prefer runit. It is built on solid principles (daemontools), and for my preferred distribution (Debian and Ubuntu) it is nicely packaged by the author himself.

Despite being recommended in other answers, and mentioned in comments, starting a long running process in screen/tmux, or via nohup is sub-optimal. 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. 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.

This is because killing the shell that started a process (e.g. by logging out) will kill process to unless they're background processes. Screen works since as well since it runs in the background, and screen effectively keeps your session running while you attach/detach.


One way is to use nohup

nohup java -jar start.jar

This has the advantage of writing stdout and stderr to a file

Another way would be to use screen


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). There's one at 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. So will putting the process in the background with &.

0

精彩评论

暂无评论...
验证码 换一张
取 消