Home > Node Manager, oracle, Weblogic > Node Manager as Linux service and Weblogic server autorestart

Node Manager as Linux service and Weblogic server autorestart

In order to have Node Manager start automatically it must be configured as a daemon. In order to do that, edit the below script to reflect your Weblogic installation path, then save it under /etc/init.d/nodemgr and run ‘chkconfig –add nodemgr’ as root.

#!/bin/sh
#
# nodemgr Oracle Weblogic NodeManager service
#
# chkconfig:   345 85 15
# description: Oracle Weblogic NodeManager service
# The script needs to be saved as /etc/init.d/nodemgr and then issue chkconfig –add nodemgr as root

### BEGIN INIT INFO
# Provides: nodemgr
# Required-Start: $network $local_fs
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Oracle Weblogic NodeManager service.
# Description: Starts and stops Oracle Weblogic NodeManager.
### END INIT INFO

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

export MW_HOME=”/w01/oracle/bea”
export JAVA_HOME=”/w01/jrrt-3.1.2-1.6.0″
DAEMON_USER=”oracle”
PROCESS_STRING=”^.*/w01/oracle/bea/.*weblogic.NodeManager.*”

source $MW_HOME/wlserver_10.3/server/bin/setWLSEnv.sh > /dev/null
export NodeManagerHome=”$WL_HOME/common/nodemanager”
NodeManagerLockFile=”$NodeManagerHome/nodemanager.log.lck”

PROGRAM=”$MW_HOME/wlserver_10.3/server/bin/startNodeManager.sh”
SERVICE_NAME=`/bin/basename $0`
LOCKFILE=”/var/lock/subsys/$SERVICE_NAME”

RETVAL=0

start() {
OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
if [ ! -z “$OLDPID” ]; then
echo “$SERVICE_NAME is already running (pid $OLDPID) !”
exit
fi

echo -n $”Starting $SERVICE_NAME: “
/bin/su $DAEMON_USER -c “$PROGRAM &”

RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
}

stop() {
echo -n $”Stopping $SERVICE_NAME: “
OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
if [ “$OLDPID” != “” ]; then
/bin/kill -TERM $OLDPID
else
/bin/echo “$SERVICE_NAME is stopped”
fi
echo
/bin/rm -f $NodeManagerLockFile
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE

}

restart() {
stop
sleep 10
start
}

case “$1” in
start)
start
;;
stop)
stop
;;
restart|force-reload|reload)
restart
;;
condrestart|try-restart)
[ -f $LOCKFILE ] && restart
;;
status)
OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING`
if [ “$OLDPID” != “” ]; then
/bin/echo “$SERVICE_NAME is running (pid: $OLDPID)”
else
/bin/echo “$SERVICE_NAME is stopped”
fi
RETVAL=$?
;;
*)
echo $”Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}”
exit 1
esac
exit $RETVAL
 

Now the Node Manager can be controlled via the service command, for example to restart NM:

service nodemgr restart

With the NM restarting automatically after a system reboot, you might want the Weblogic managed server to act the same. To have the managed servers automatically restarted by Node Manager, you must activate the Autorestart option in the Administration Console as well as set the CrashRecoveryEnabled to ‘true’ in $WL_HOME/wlserver_10.3/common/nodemanager/nodemanager.properties.

Notice that the weblogic servers will be restarted after a machine reboot only if they were actually running at the time the shutdown command was issues.

You can also download the script in Unix format, by right clicking this link, ‘Save Link  as…’ and then use it on Linux by removing the extension.

Advertisements
  1. Vasan
    February 17, 2012 at 7:42 am

    No matter what I try the line “echo $”Usage:……….” continues to fail with “Command not found for each item in the list” I am using this Oracle Weblogic 12c on RHEL 5
    PLEASE HELP!
    Thanks in advance
    Vasan

  2. radudobrinescu
    February 17, 2012 at 8:18 am

    Hi Vasan,

    For me it works as expected:

    [oracle@fmw1 ~]$ echo $”Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}”
    Usage: -bash {start|stop|status|restart|reload|force-reload|condrestart}

    Can you make sure you have the ‘echo’ in the PATH? Execute ‘which echo’, it should return something like:

    [oracle@fmw1 ~]$ which echo
    /bin/echo

  3. Vasan
    February 18, 2012 at 4:40 am

    Thanks.
    But, I resolved that problem – it was a minor syntax error.
    But now, I keep getting the error “line82:syntax error: unexpected end of file”, though the last line in the script is line81.
    Several searches on goole, told me that some earlier process is not closed. This is why the end command “esac” throws an error.
    I checked every line for all closed quotes and brackets.
    Still can’t find the issue.
    Any help is highly appreciated.

    • radudobrinescu
      February 18, 2012 at 8:04 am

      If you are having synthax problems I suggest downloading the pdf file from the link at the end of the post, rather than copy-pasting the script from the post. It should not be a pdf file of course, but wordpress doesn’t allow .sh files. Simply download the file, change the extension and use it on your RHEL5 machine.

      Thanks,
      Radu

  4. June 8, 2012 at 6:21 am

    The document is not the PDF document. It is a text document. After download rename it to txt or something. Using the document is much simpler than copy+paste the contents manually…

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: