How exactly do servers shut themselves down?
For e.g. a Web server it just keeps waiting for clients in a infinite loop. So how is it supposed to actually exit itself.
One way I can think of is by using a signal handler. I mean when the server is started initially it "takes over" a certain port after this if we try to start the same server again we will be unable to do so as the port will be occupied. This lets us know that our(?) server is already running.
Now if I need to shutdown this server I send a special arg say -close and this sends a signal to the running server (how do i get the PID now?) which terminates itself.
Is there a cleaner way to do this?
And yeah the main thing. How is this done in JAVA?
Shutting down a server
Re:Shutting down a server
Apache has a 'master' thread that takes a signal and asks the threads to all terminate themselves (close the listening socket , wait for the current sockets to finish up and close, then exit), followed by the master exiting (so clients still get whole files). The signal approach is pretty common in unix, with the daemon putting it's PID in a pid file somewhere like /var/run.... seems pretty clean to me
Another technique I've seen used is to have a direct communication channel with a shutdown command (perhaps password protected 'admin' mode).
(whuddya mean by 'java'? jvm's have loads of interesting facilities that allow things like object spaces (tuple space), rmi, various jvm interfaces .... it's pretty much an emulated os...)
-Erik
Another technique I've seen used is to have a direct communication channel with a shutdown command (perhaps password protected 'admin' mode).
(whuddya mean by 'java'? jvm's have loads of interesting facilities that allow things like object spaces (tuple space), rmi, various jvm interfaces .... it's pretty much an emulated os...)
-Erik
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Shutting down a server
This might help you:
http://builder.com.com/5100-6370-5144546.html
I usually just make the background threads test a "cancel" flag in their loop, and exit if the flag is true. Testing and setting the flag must be done atomically.
http://builder.com.com/5100-6370-5144546.html
I usually just make the background threads test a "cancel" flag in their loop, and exit if the flag is true. Testing and setting the flag must be done atomically.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager
Re:Shutting down a server
I am going through the link you gave.
I have a question though.
How do you write a daemon in Java?
I have a question though.
How do you write a daemon in Java?
Only Human
Re:Shutting down a server
Guess its not that easy huh.
http://jakarta.apache.org/commons/daemon/
http://jakarta.apache.org/commons/daemon/
Only Human
Re:Shutting down a server
I guess the Java "write once, run everywhere" thing was just a hype.
There seems to be no way you can write a daemon entirely in Java that would run on both *nix and Windows. It seems it would need separate binary helpers (in C most probably) for each platform to make the Java server run as a daemon/service.
There seems to be no way you can write a daemon entirely in Java that would run on both *nix and Windows. It seems it would need separate binary helpers (in C most probably) for each platform to make the Java server run as a daemon/service.
Only Human