Jetty server stops running after closing terminal window

10,491

Solution 1

It sounds like you're using ssh or something like that to start Jetty on a remote Linux/Unix server.

So, you can use nohup java -jar start.jar & - nohup will prevent your process from being stopped by the usual Unix "hangup" signal (ref) when you log out, and the & will put jetty as a background process so you can type exit or whatever to log out.

If you want to be able to re-attach to the Jetty terminal, I'd recommend reading up on GNU screen.

If you want to stop jetty gracefully again, I'd really recommend using it as a service, or using screen to avoid losing the terminal. But if it's too late for that you can find the PID in the output of jps -l and then call kill $PID.

Solution 2

try "nohup java -jar start.jar &"

and i'm already say it in previous question )

Solution 3

How to kill process:

1) java style

when start jetty :

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar

for stop:

java -DSTOP.PORT=8077 -DSTOP.KEY=secret_key_only_admin_know -jar start.jar -stop

P.S. ports can be any - but they must be the same for start and kill commands :)

2) linux style

kill process by PID

Solution 4

You can properly install it as a linux service(if you are actually connecting to a linux server) too.

cd to your jetty folder, for example mine is:

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/

sudo cp ./bin/jetty.sh /etc/init.d/jetty

Then open the file with your favorite text editor, like vim or nano

sudo vim /etc/init.d/jetty

In the beginning simply uncomment(simply 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 looks like this:

#!/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
# ========================

(You don't actually need to uncomment those three lines for it to work, only add the jetty_home. But for a proper deploy you should probably fix those lines.)

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 boot, 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.

Solution 5

You can set up jetty to run as a service... here's the instruction for linux and windows. This way, you don't need to worry about launching jetty everytime through the terminal.

Share:
10,491
einstein
Author by

einstein

Updated on June 09, 2022

Comments

  • einstein
    einstein almost 2 years

    I am a newbie when it comes to Java and Jetty app deployment. I use the default settings for setting up my jetty serve and ran java -jar start.jar on my terminal window. The server runs as expected, but when I close my terminal it stops. Is this normal? I used XAMPP before and there you can close the terminal without any problem. How do I overcome this problem, everybody needs to shut down there personal computer once in a while.

    I'm using a mac btw.