[CentOS] starting a java application as a service

James B. Byrne ByrneJB at Harte-Lyne.ca
Mon Oct 24 21:19:25 UTC 2005

I have a single requirement to launch a java application on startup 
as a service.  The application is shipped in a file called jes.jar. 
 It requires three arguments: a dotted quad IP address,  an initial 
service port, and a translated service port.

I can get the application running as a console command.  Can 
someone point me to a site that documents how to script a sys V 
init.d style script so that I can run this as a daemon process?  I 
tried copying a script in the age old fashion but I seem to be 
missing something(s).

Lastly, I vaguely recall that there is a way to capture the pid of 
a program started in the shell but I cannot find any reference to 
it.  I seem to recall that the construct $! or $$ contained the 
value of the last program run.  Can anyone here confirm this and/or 
provide an example.

I am a digest subscriber so direct responses are appreciated (reply 
to all).

Sample script

# jes:          Java Encryption Server for Javelin NSTV 
# chkconfig:    - 26 89
# description:	Java Encryption Service to support SSL 
# 				connections for the  Javelin HP3000 NS/VT 
#				emulator java applette.

#       Check if config file readable (and therefore exists).
[ -r /etc/sysconfig/jes ] || exit 0

#       Read and execute the config file.
. /etc/sysconfig/jes

#       Check if variable has length zero and exit if true.
[ -z "$JESARGS" ] && exit 0

        echo -n $"Starting jes as daemon: "
        /usr/bin/java -cp /usr/local/lib/java/jes.jar Jes $JESARGS
        touch /var/lock/subsys/jes

        echo -n $"Shutting down jes (Java Encryption Service): "
        /usr/bin/jes -K
        killproc jes

        rm -f  /var/lock/subsys/jes

[ -f /usr/bin/jes ] || exit 0

# See how we were called.
case "$1" in
        [ -e /var/lock/subsys/jes ] && (stop; start)
        echo $"Usage: $0 {start|stop|restart|reload|condrestart}"
        exit 1

exit 0

sample configuration file:

# Options to Jes server for secure javelin connections
# VTNAME IP address of NSVT host (usually an HP3000)

# VTPORT The service port that the NSVT service is listening 
#		on (Usually 1570)

# JESPORT 	The service port that JES listens to on this host for VT
#			Javelin	connections.  This can be any port but it is 
#			required that:
#				a.	This port must be allowed through any exterior 
#					firewalls.
#		         b.	The client must have the same port configured 
#					in default.j92
#					(or encrypt.j92 if that is what you are using).

# These are concatenated here for use in the init.d script.

     *** e-mail is not a secure channel ***
James B. Byrne                Harte & Lyne Limited
vox: +1 905 561 1241          9 Brockley Drive
fax: +1 905 561 0757          Hamilton, Ontario
<token> = hal                 Canada L8E 3C3

More information about the CentOS mailing list