Thursday, December 24, 2009

Starting Weblogic after reboot

Here is a (linux) script that can be used during for starting Oracle Weblogic during startup and shutdown of the machine. The script only a framework that is at the various run-levels. The actual code of stopping and starting WLS is in another script (/home/oracle/bin/wls.sh).

Create the folloing script in /etc/init.d (as root)

/etc/init.d/oracle-wls
#!/bin/bash
#
# /etc/rc.d/init.d/oracle-wls
#
# Starts the weblogic environment
#
# chkconfig: 2345 90 10
# description: Oracle-WLS Daemon

# processname: oracle-wls

source /etc/rc.d/init.d/functions

### Default variables
SYSCONFIG="/etc/sysconfig/oracle-wls"

### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="/home/oracle/bin/wls.sh"
desc="Oracle WLS Daemon"
SU=/bin/su
SHELL=/bin/bash

START_AS_USER=oracle

start() {
echo -n $"Starting $desc ($prog): "
$SU -s $SHELL $START_AS_USER -c "$prog start" > /dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
echo
}

stop() {
echo -n $"Shutting down $desc ($prog): "
$SU -s $SHELL $START_AS_USER -c "$prog stop" > /dev/null 2>&1
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart}"
RETVAL=1
esac

exit $RETVAL

Make the script known the O/S for the various boot levels (as root):
chkconfig --add oracle-wls  && chkconfig oracle-wls on
You can test the script (as root)

# service oracle-wls stop
Shutting down Oracle WLS Daemon (/home/oracle/bin/wls.sh): [ OK ]

# service oracle-wls start
Starting Oracle WLS Daemon (/home/oracle/bin/wls.sh): [ OK ]