Wiki
Clone wikiShampoo / JettyNetBSDRcD
Example rc.d script for NetBSD
Here's an example Jetty boot script for NetBSD, save it as /etc/rc.d/jetty.
#!/bin/sh # # $NetBSD: jetty.sh,v 0.1 2011/11/10 19:22:45 okay_awright Exp $ # # PROVIDE: jetty # REQUIRE: DAEMON # AFTER: network mysqld . /etc/rc.subr if [ -z "${JAVA_HOME}" ] then #Uses a custom-built x64 JVM: http://java.net/projects/shampoo/downloads/directory/Misc JAVA_HOME="/usr/pkg/java/openjdk7" export JAVA_HOME fi if [ -z "${JAVA_OPTS}" ] then #Common switches JAVA_OPTS="-server -Xms512M -Xmx1536M -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true" #Can upload files that weight up to 2Gb though HTTP POST if needed JAVA_OPTS="${JAVA_OPTS} -Dorg.eclipse.jetty.server.Request.maxFormContentSize=2000000000" #Oracle HotSpot 6/7 JAVA_OPTS="${JAVA_OPTS} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jetty -XX:ErrorFile=/var/log/jetty/hs_err_pid%p.log" JAVA_OPTS="${JAVA_OPTS} -XX:-ReduceInitialCardMarks -XX:MaxPermSize=128M" #Uncomment for JMX monitoring #JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1099" export JAVA_OPTS fi if [ -z "${JAVA}" ] then JAVA="${JAVA_HOME}/bin/java" export JAVA fi TMPDIR=${TMPDIR:-/var/tmp} name="jetty" rcvar=${name} jar="-jar start.jar" pidfile="/var/run/jetty/${name}.pid" : ${jetty_port="8080"} : ${jetty_user="jetty"} : ${jetty_group="jetty"} : ${jetty_home="/usr/local/java/jetty"} : ${jetty_logs="/var/log/jetty"} : ${jetty_dirs="/var/log/jetty /var/run/jetty"} extra_commands="status" start_cmd="jetty_start" stop_cmd="jetty_stop" status_cmd="jetty_status" restart_cmd="jetty_restart" start_precmd="jetty_prestart" if [ "${jetty_port}" ] then JAVA_OPTS="${JAVA_OPTS} -Djetty.port=${jetty_port}" fi if [ "${jetty_logs}" ] then JAVA_OPTS="${JAVA_OPTS} -Djetty.logs=${jetty_logs}" fi JAVA_OPTS="${JAVA_OPTS} -Djetty.home=${jetty_home} -Djava.io.tmpdir=${TMPDIR} " if [ -f "${jetty_home}/etc/start.config" ] then JAVA_OPTS="${JAVA_OPTS} -DSTART=${jetty_home}/etc/start.config" fi jetty_prestart() { for dir in ${jetty_dirs}; do mkdir -p $dir chown ${jetty_user}:${jetty_group} $dir chmod 0750 $dir done } jetty_start() { echo "Starting ${name}." if [ -f ${pidfile} ]; then pid=`head -1 ${pidfile}` echo "${name} already running as pid ${pid}." return 1 fi cd ${jetty_home} && su -m ${jetty_user} -c "export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:${JAVA_HOME}/bin; # Update memory and files thresholds enforced by the system, check if your Kernel can witholhd those values ulimit -n unlimited; ulimit -s unlimited; ulimit -m unlimited; ulimit -d 1040288; ulimit -l 1040288; ${JAVA} ${JAVA_OPTS} ${jar} ${rc_flags} &" && cd - sleep 1 PID="`ps -ax|grep "${JAVA}"|grep "-server"|grep -v grep|awk '{print $1;}'`" if [ "${PID}" != "" ]; then su -m ${jetty_user} -c "echo ${PID} > ${pidfile}" fi } jetty_stop() { echo "Stopping ${name}." if [ -f ${pidfile} ]; then pid=`head -1 ${pidfile}` if [ "${pid}" != "" ]; then #BUG?: Jetty refuses to cleanly die on OpenJDK7 (2009) #doit="su -m ${jetty_user} -c \"kill ${pid}\"" #if ! eval $doit && [ -z "$rc_force" ]; then # return 1 #fi #wait_for_pids $pid echo -n '[' for WAIT in 1 2 3 4 5 6 7 8 9 10 do if kill -0 ${pid} >/dev/null 2>&1; then sleep 2 echo -n '.' test $WAIT -lt 10 || kill -9 ${pid} else break fi done echo ']' unset WAIT else echo "${name} is not running?" fi rm -f ${pidfile} else echo "${name} is not running?" fi } jetty_status() { echo "Polling ${name}." if [ -f ${pidfile} ]; then pid=`head -1 ${pidfile}` echo "${name} is running as pid ${pid}." else echo "${name} is not running?" fi } jetty_restart() { jetty_stop jetty_start } load_rc_config $name run_rc_command "$1"
Now, edit your /etc/rc.conf file and add the following line wherever you see fit, most likely at the end of the file:
jetty=YES
Updated