아래 스크립트에서 각 환경에 맞게 수정할 변수는 이 5개 이다.
#!/bin/sh
#
# chkconfig: 35 99 01
# description: java application
#
java=/usr/java/default
prog=javarun
jarprog=/usr/java/apps/javarun.jar
jarlib=/usr/java/apps/lib
javaoptions=
pidfile=/var/run/${prog}.pid
logfile=/var/log/${prog}.log
lockfile=/var/lock/subsys/${prog}
cmdline="${java}/bin/java -jar ${jarprog} ${javaoptions}"
RETVAL=0
# System configuration
unset TMPDIR
if [ -f /etc/sysconfig/${prog} ]; then
. /etc/sysconfig/${prog}
fi
# Source function library
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 1
fi
start() {
echo -n $"Starting ${prog} services: "
daemon --pidfile=${pidfile} "${cmdline} &"
RETVAL=$?
pgrep -f "${jarprog}" > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch ${lockfile} || RETVAL=1
return $RETVAL
}
stop() {
echo -n $"Stopping ${prog} service: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f ${lockfile} ${pidfile}
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} ${prog}
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: ${prog} {start|stop|status|restart}: "
RETVAL=2
esac
exit $RETVAL