Start up on boot for Linux

This is a useful script for starting up LAMS on boot

For JBoss 5.1

Create a file called lams2 in /etc/init.d/ and modify the script below to fit your JAVA_HOME, IP, _JBOSS_USER, etc.

#!/bin/sh  
# lams2        This shell script takes care of starting and stopping 
#               the MySQL subsystem (mysqld). 
# 
# chkconfig: 2345 90 20 
# description:  LAMS 2. 
# processname: java 
# 
#               Written by Miquel van Smoorenburg <miquels@cistron.nl>. 
#               Modified for Debian  
#               by Ian Murdock <imurdock@gnu.ai.mit.edu>. 
#               Modified for LAMS  
#               by Ernie Ghiglione <ernieg@lamsfoundation.org>. 
# 
# Version:      @(#)skeleton  1.9  26-Feb-2001  miquels@cistron.nl 
# 
 
# Attempt to locate JAVA_HOME, code borrowed from jabref package 
 
if [ -z $JAVA_HOME ] 
then 
        t=/usr/lib/jvm/java-1.5.0-sun && test -d $t && export JAVA_HOME=$t 
        t=/usr/lib/jvm/java-6-sun && test -d $t && export JAVA_HOME=$t 
fi 
JBOSS_USER=jboss 
JAVA_HOME=/usr/lib/jvm/java-6-sun 
PATH=/sbin:/bin:/usr/sbin:/usr/bin:${JAVA_HOME}/bin 
JAVA=${JAVA_HOME}/bin/java 
JBOSS_HOME=/usr/local/jboss-5.1
NAME=default
IP=127.0.0.1
DESC="LAMS 2 Server $NAME" 
 
test -x $JAVA || exit 0 
 
# Read an optional running configuration file 
if [ "x$RUN_CONF" = "x" ]; then 
    RUN_CONF="${JBOSS_HOME}/bin/run_$NAME.conf" 
fi 
if [ -r "$RUN_CONF" ]; then 
    . "$RUN_CONF" 
fi 
 
# Setup the java endorsed dirs 
JBOSS_ENDORSED_DIRS="$JBOSS_HOME/lib/endorsed" 
 
# Setup the classpath 
runjar="$JBOSS_HOME/bin/run.jar" 
if [ ! -f "$runjar" ]; then 
    die "Missing required file: $runjar" 
fi 
JBOSS_BOOT_CLASSPATH="$runjar" 
 
# Include the JDK javac compiler for JSP pages. The default is for a Sun JDK 
# compatible distribution which JAVA_HOME points to 
if [ "x$JAVAC_JAR" = "x" ]; then 
    JAVAC_JAR="$JAVA_HOME/lib/tools.jar" 
fi 
 
if [ "x$JBOSS_CLASSPATH" = "x" ]; then 
    JBOSS_CLASSPATH="$JBOSS_BOOT_CLASSPATH:$JAVAC_JAR" 
else 
    JBOSS_CLASSPATH="$JBOSS_CLASSPATH:$JBOSS_BOOT_CLASSPATH:$JAVAC_JAR" 
fi 
 
DAEMON_OPTS="$JAVA_OPTS -Dfile.enconding=UTF8 -Djava.endorsed.dirs=$JBOSS_ENDORSED_DIRS -classpath $JBOSS_CLASSPATH -Dprogram.name org.jboss.Main -b $IP -c $NAME" 
 
#set -e 
start() { 
        start-stop-daemon --start --chuid $JBOSS_USER --quiet --background --make-pidfile --pidfile $JBOSS_HOME/$NAME.pid --exec $JAVA -- $DAEMON_OPTS 
 
} 
 
stop() { 
        start-stop-daemon --stop --quiet --pidfile $JBOSS_HOME/$NAME.pid 
} 
 
case "$1" in 
  start) 
        echo "$DESC is starting up." 
        start 
        ;; 
  stop) 
        echo -n "Stopping $DESC... " 
        stop 
        rm -f /var/run/$NAME.pid 
        echo "stopped." 
        ;; 
  status) 
        if [ -e /var/run/$NAME.pid ]; then 
            if [ -r /var/run/$NAME.pid ]; then 
                pid=`cat /var/run/"$NAME".pid` 
                if [ "X$pid" = "X" ]; then 
                    echo "$DESC is not running." 
                    exit 1 
                else 
                    echo "$DESC is running ($pid)." 
                    exit 0 
                fi 
            fi 
        fi 
        echo "$DESC is not running." 
        ;; 
  restart|force-reload) 
        # 
        #       If the "reload" option is implemented, move the "force-reload" 
        #       option to the "reload" entry above. If not, "force-reload" is 
        #       just the same as "restart". 
        # 
        echo -n "Restarting $DESC: " 
        #set +e 
        stop 
        #set -e 
        sleep 10 
        start    
        ;; 
  *) 
        N=/etc/init.d/$NAME 
        echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 
        exit 1 
        ;; 
esac 
 
exit 0 

In Centos/RHEL5

In Centos/RHEL5, make sure you download the start-stop-daemon source and compile as follows

# wget "http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz"
# tar xvzf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz 
# cd apps/sys-utils/start-stop-daemon-IR1_9_18-2/
# gcc start-stop-daemon.c -o start-stop-daemon
# cp start-stop-daemon /usr/sbin/

Add lams2 script to unix services

Ubuntu

sudo update-rc.d lams2 defaults

CentOS/RHEL5

chkconfig --levels 235 lams2 on