简体   繁体   中英

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. 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 (eg 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.

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 & .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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