Hi,
I have a custom Java application that needs to be controlled by the
/etc/init.d/ facillity on a Linux server. I want this to work exactly
like Apache or any other service running on the machine, so that as
root I can type:
/etc/init.d/javaserver start
/etc/init.d/javaserver stop
/etc/init.d/javaserver restart
To start, stop, and restart this service, and allow this service to be
automatically stopped and started on shutdown and boot of the machine.
On restart and stop, the application must be alerted in some way so
that it can gracefully release client connections and SQL database
connections. I can code anything in Java, but the answer to this
question must say how my code will know how to enter the "shutdown"
mode and start releasing connections. Maybe Java has some kind of
facillity to get process messages like C programs (SIGHUP).
I am looking for the shell script that will do this, and an
explanation of how to let my Java code know when there is a "stop"
event. I am familiar with RedHat Linux's /etc/init directory structure
to control which runlevels a service is run, and so don't need an
explanation of how to use the script.
I will have multiple copies of this service running on different JVM's
(ie: javaserver_beta, javaserver_development, javaserver_production)
that are bound to different ports or IP's on the same machine, so a
script that uses a simple "ps -ef | grep java | sed | kill ..." will
not work. This needs to know which JVM to kill or send the message to.
Thank you.
Matt. |