Java services on Linux December 15, 2005
Posted by Jerome Louvel in Java, Linux.6 comments
After spending quite a bit of time today figuring out how to properly register a Java-based server as a Linux service on Debian Sarge, I thought I would share the results of my findings. My requirements were:
- Automatically start, stop and restart
- Cleanly integrate with other system services
- Run the Java processes under a non-root user
Here is the script template that can be added to /etc/init.d :
#! /bin/sh
#
# -----------------------------------
# Initscript for the ...
# -----------------------------------
#
# This controls the ...
#
# Author: Jerome Louvel .
#
# Version: @(#)daemon 1.0 16-Dec-2005 ...@...
#
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="My daemon"
NAME=daemon
USER="prod"
HOME="/home/prod"
CP="...classpath..."
MAIN="...main class..."
ARGS="...main arguments..."
DAEMON="/usr/bin/java -server -cp $CP -Djava.awt.headless=true $MAIN $ARGS"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x /usr/bin/java || exit 0
# ---------------------------------------
# Function that starts the daemon/service
# ---------------------------------------
d_start()
{
su -p -s /bin/sh - $USER "$DAEMON &> /dev/null & echo $!" > $PIDFILE
}
# --------------------------------------
# Function that stops the daemon/service
# --------------------------------------
d_stop()
{
start-stop-daemon --stop --quiet --pidfile $PIDFILE
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
Here are the related resources I found:
- Jetty start script
- Jetty start script for the Debian package (see end of diff file)
- Tomcat start script
Update: the script was modified from the initial post to follow more closely the /etc/init.d/skeleton script provided with Debian.
RESTful programming frameworks December 9, 2005
Posted by Jerome Louvel in Restlet General.add a comment
In today’s post , Mark Baker describes the desirable properties of such framework:
- don’t hide the resource-centric REST model from developers
- Web based models should resemble HTTP Servlets
- objects/services should expose the uniform interface.
If you know how Restlets work, you certainly recognized those properties. A new idea I noted though: facilitate dealing with resource collections.
Suggestions for Restlets December 9, 2005
Posted by Jerome Louvel in Restlet General.add a comment
The last couple of days, I received some encouraging feed-back from an early REST advocate: Jean-Paul Figer. He helped me to identify the following needs:
- Filtering Restlet for logging, security, etc. : similar in purpose to Servlet Filters (already added to the upcoming 0.15 beta)
- Integration with existing Web servers (Apache and Microsoft IIS) : this is especially useful if Restlets are to be effectively used in corporate environment -> integrate Apache Tomcat connectors
- Support XML configuration of Restlet servers (containers, Restlets, URI mappings, etc.). This is important if Restlets are to be used by non Java programmers and also for administration purpose.
- Add support for “URI rewriting” in a simpler manner than IIS or Apache -> use the Filter concept to implement internal redirects, client-based redirects and proxy-based transparent redirects.
In addition, here are the other new features high on the to do list:
- Logging Restlet generating logs similar to Apache -> LogFilter
- Extend the JDBC connector to support features like SQL in / XML out in Oracle database and related standards (http://sqlx.org).
- Extend the JDBC connector to support XQuery style requests returning XML representation.
Any other idea? Please join the project at http://www.restlet.org and submit your ideas.
