rc script for Jetty 6
Ashley Moran
work at ashleymoran.me.uk
Thu May 25 07:18:55 PDT 2006
After two days pulling my hair out with Jetty 5 I installed Jetty 6 manually.
It works but there's no real way to start and stop it, so I started writing
an rc script. Eventually I figured out it would be almost identical to the
Tomcat script so I've prepared a modified version (below). Thought I'd post
it in case anyone else uses Jetty 6.
As far as I can see it's almost identical to the Tomcat one but there's two
problems:
- stop doesn't work the same (I've had to put a hack in) because $rc_pid is
not being set. no idea why...
- the process in the output of "ps -aux" shows in full command line form, like
this:
jetty 69487 ... 2:57PM 0:05.31 /usr/local/jdk1.5.0/bin/java ...
while the output for Tomcat shows like this:
www 13404 ... 3:13PM 0:02.20 [java]
(Actually I think the second problem is the cause of the first.)
I'm not much of an rc guru. Does anyone know where I'm going wrong?
Ashley
#!/bin/sh
# PROVIDE: jetty6
# REQUIRE: NETWORKING SERVERS
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Script to start and stop Jetty 6
# Expects a file at ${jetty6_home}/etc/jetty.conf containing a list of
# config files to read on startup
#
# Configuration lines you can add to /etc/rc.conf
# jetty6_enable (bool): Set to "NO" by default, set it to "YES" to enable
Jetty
# jetty6_user (str): Defaults to "jetty"
# jetty6_home (str): Defaults to "/usr/local/share/java/jetty6"
# jetty6_log (str): Defaults to "${jetty6_home}/logs/jetty.log"
# jetty6_stop_timeout (num): Number of seconds waited when stopping Jetty
before
# the process is killed. Defaults to 10
# jetty6_java_home (str):
# jetty6_java_vendor (str):
# jetty6_java_version (str):
# jetty6_java_os (str):
# Specify the requirements of the Java VM to use. See javavm(1).
# jetty6_jvm_options (str): Java VM args
#
# set defaults
jetty6_enable="${jetty6_enable:-"NO"}"
jetty6_java_version="${jetty6_java_version:-"1.4+"}"
jetty6_home="${jetty6_home:-"/usr/local/share/java/jetty6"}"
jetty6_user="${jetty6_user:-"jetty"}"
jetty6_jvm_options="${jetty6_jvm_options:-""}"
jetty6_log="${jetty6_log:-"${jetty6_home}/logs/jetty.log"}"
jetty6_stop_timeout="${jetty6_stop_timeout:-"10"}"
. /etc/rc.subr
name="jetty6"
rcvar=`set_rcvar`
pidfile="/var/run/${name}.pid"
load_rc_config "$name"
if [ -n "${jetty6_java_home}" ] ; then
export JAVA_HOME="${jetty6_java_home}"
fi
if [ -n "${jetty6_java_version}" ] ; then
export JAVA_VERSION="${jetty6_java_version}"
fi
if [ -n "${jetty6_java_vendor}" ] ; then
export JAVA_VENDOR="${jetty6_java_vendor}"
fi
if [ -n "${jetty6_java_os}" ] ; then
export JAVA_OS="${jetty6_java_os}"
fi
java_command="/usr/local/bin/java \
$jetty6_jvm_options \
-jar /usr/local/share/java/jetty6/start.jar"
# Subvert the check_pid_file procname check.
if [ -f $pidfile ]; then
read rc_pid junk < $pidfile
if [ ! -z "$rc_pid" ]; then
procname=`ps -o comm= $rc_pid`
fi
fi
required_files="${jetty6_home}/etc/jetty.conf"
command="/usr/sbin/daemon"
flags="-p ${pidfile} ${java_command} ${jetty6_configs} >> ${jetty6_log} 2>&1"
start_precmd="jetty6_start_precmd"
stop_cmd="jetty6_stop"
jetty6_start_precmd()
{
touch $pidfile
chown $jetty6_user $pidfile
# read in list of configs from master config file
# process them relative to $jetty6_home
if [ -f "${jetty6_home}/etc/jetty.conf" ] &&
[ -r "${jetty6_home}/etc/jetty.conf" ]
then
jetty6_configs=`cat ${jetty6_home}/etc/jetty.conf \
| grep -v "^[:space:]*#" \
| awk -v JH=$jetty6_home 'length > 0 { print JH "/" $1 }'
\
| tr "\n" " "`
else
echo "Can't read list of configs from ${jetty6_home}/etc/jetty.conf"
exit 1
fi
}
jetty6_stop() {
# not sure why this doesn't work
#rc_pid=$(check_pidfile $pidfile $procname)
rc_pid=`cat $pidfile`
if [ -z "$rc_pid" ]; then
[ -n "$rc_fast" ] && return 0
if [ -n "$pidfile" ]; then
echo "${name} not running? (check $pidfile)."
else
echo "${name} not running?"
fi
return 1
fi
echo "Stopping ${name}."
${java_command} --stop
jetty_wait_max_for_pid ${jetty6_stop_timeout} ${rc_pid}
kill -KILL ${rc_pid} 2> /dev/null && echo "Killed."
echo -n > ${pidfile}
}
jetty_wait_max_for_pid() {
_timeout=$1
shift
_pid=$1
_prefix=
while [ $_timeout -gt 0 ] ; do
echo -n ${_prefix:-"Waiting (max $_timeout secs) for PIDS: "}$_pid
_prefix=", "
sleep 2
kill -0 $_pid 2> /dev/null || break
_timeout=$(($_timeout-2))
done
if [ -n "$_prefix" ]; then
echo "."
fi
}
run_rc_command "$1"
--
"If you do it the stupid way, you will have to do it again"
- Gregory Chudnovsky
More information about the freebsd-questions
mailing list