Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Sending shutdown signal to JVM

Thread view: 
manish - 27 Jan 2007 08:45 GMT
Hi, I'm writing a java daemon process. Starting the process up is fine,
(e.g. java -server Main args). However in order to shutdown the process
I have to manually kill the process (e.g. kill pid). However, if there
are many java server processes running on the box it is easy to kill
the wrong process. There must be a better way to do this, here are some
of the options I can think of:

1) Put the process id in a file.
2) Change the server process so that it listens on a port for a
shutdown command.
3) Change the server process so that it polls a directory for a file
containing the shutdown command.
4) Change the server process so that it registers to an rmiregistry and
can have shutdown called on it.

Does anyone have any other ideas? - I'm just trying to find the
cleanest and simplest method of shutting down the server that has the
minimal impact on the code and ensure that the correct jvm is shutdown.
(Pls note that I'm aware of the Runtime.addShutdownHook method)
thanks. :)
Kai Schwebke - 27 Jan 2007 13:38 GMT
manish schrieb:
> Hi, I'm writing a java daemon process. Starting the process up is fine,
...

Hava a look at jsvc -- it's the wrapper also used by tomcat
(http://jakarta.apache.org/commons/daemon/jsvc.html).

It provides a complete framework for java daemons including changing
user id after init.

Kai
Martin Gregorie - 27 Jan 2007 20:30 GMT
> Hi, I'm writing a java daemon process. Starting the process up is fine,
> (e.g. java -server Main args). However in order to shutdown the process
> I have to manually kill the process (e.g. kill pid). However, if there
> are many java server processes running on the box it is easy to kill
> the wrong process. There must be a better way to do this, here are some
> of the options I can think of:

...
> 1) Put the process id in a file.

This is useful if you're running in a Linux/UNIX environment that uses
scripts in /etc/rc.d/init.d to control permanent servers, i.e. the
method used by RedHat and others. By doing this you get to use the
"chkconfig" command to control server startup order and the run levels
it runs in. You also get to use the "service" command to start, stop,
restart and inquire on the status of the server. This approach will keep
a simple server simple because all the control functions can be handled
via a straight forward shell script, but it isn't a portable solution.

> 2) Change the server process so that it listens on a port for a
> shutdown command.

This works well for servers in any language. If the server is already
using sockets it probably has little effect on its overall logical
structure. I find that the command interface is also a good way of
checking status, controlling operation, e.g. turning diagnostics on and
off for a running process. I usually write a simple client that provides
a command line interface to send commands and interpret and display the
responses and can be included in scripts.

Possibly its biggest benefit is that it makes controlling the server
independent of the OS, which can be a big help to portability, and also
adds the possibility controlling it remotely at no additional cost.

> 3) Change the server process so that it polls a directory for a file
> containing the shutdown command.

That sounds rather like adding a wart to the server. Reading the file
frequently enough to get a fairly instant response quite probably adds a
performance overhead.

> 4) Change the server process so that it registers to an rmiregistry and
> can have shutdown called on it.

No comment: never tried it.

>  Does anyone have any other ideas?

Your option (2) could add a lot of flexibility, such as letting a
scheduler to issue commands via the control client. If the server
accepts "deactivate" and "activate" commands then a backup script could
use the client to pause the server while an associated database is
backed up.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

manish - 28 Jan 2007 13:23 GMT
thanks for the very useful feedback!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.