[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

#!/bin/sh
#
# jes:          Java Encryption Server for Javelin NSTV 
connections.
#
# 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

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

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

        rm -f  /var/lock/subsys/jes
        echo
}

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

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

exit 0

sample configuration file:

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

# VTPORT The service port that the NSVT service is listening 
#		on (Usually 1570)
VTPORT="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).
JESPORT="1570"

# These are concatenated here for use in the init.d script.
JESARGS="$VTNAME $VTPORT $JESPORT"

--   
     *** e-mail is not a secure channel ***
mailto:byrnejb.<token>@harte-lyne.ca
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