Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty server stops running after closing terminal window

Tags:

java

macos

jetty

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.

like image 898
einstein Avatar asked Mar 02 '11 21:03

einstein


3 Answers

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.

like image 143
Matthew Gilliard Avatar answered Oct 17 '22 05:10

Matthew Gilliard


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

like image 36
Dmytro Avatar answered Oct 17 '22 04:10

Dmytro


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.

like image 35
limc Avatar answered Oct 17 '22 05:10

limc