Weblogic Server Auto Restart with Node Manager as Linux service

Sometimes servers need to reboot and then it’s nice to have certain services to start automatically. Oracle Weblogic’s Node Manager is one of them and in order to have Node Manager start automatically it must be configured as a daemon. Unfortunately Oracle doesn’t provide init scripts to run it as a Linux service but it’s pretty simple to create your own startup scripts. Just create a new nodemgr script under /etc/init.d/, add it as a service and you’re done, as Oracle Fusion Middleware -blog writes.

For example on Red Hat Enterprise Linux Server 5.6 with Oracle Weblogic Server 10.3.5 the /etc/init.d/nodemgr looks like this (edit the script to reflect your Weblogic installation path):


#!/bin/sh
#
# nodemgr Oracle Weblogic NodeManager service
#
# chkconfig:   345 85 15
# description: Oracle Weblogic NodeManager service

### 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

# Your WLS home directory (where wlserver_10.3 is)
export MW_HOME="/oracle/product/mw11g"
export JAVA_HOME="/oracle/java/jdk1.6.0_29"
DAEMON_USER="oracle"
PROCESS_STRING="^.*/oracle/product/mw11g/.*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


Add the Node Manager to start after server reboot:

# chmod +x /etc/init.d/nodemgr
# chkconfig --add nodemgr
# chkconfig --list
nodemgr         0:off   1:off   2:off   3:on    4:on    5:on    6:off

Also now the Node Manager can be controlled via the service command (e.g. service nodemgr restart).

When you have the Node Manager restarting automatically after a system reboot, you can also have Weblogic managed servers automatically restarted by Node Manager. Managed servers will be restarted only if they were running at the time the shutdown was issued. Just activate the Auto Restart option in the Administration Console (Environment > Servers > selected server > Health Monitoring) and you might also need to set the CrashRecoveryEnabled to “true” in $WL_HOME/wlserver_10.3/common/nodemanager/nodemanager.properties.

With little scripting and configuration your sysadmin tasks have now become a little easier.

One thought on “Weblogic Server Auto Restart with Node Manager as Linux service

  1. Daniel

    I tried to use your solution and I did install it as a service.
    But on my tests trying to start, stop, restart and get the status with the command
    service nodemgr start I get this

    v121d058:/dsv/dba:service nodemgr start
    ++ CLASSPATH=/u01/app/oracle/middleware/11g/patch_wls1036/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/u01/app/oracle/middleware/11g/patch_ocp371/profiles/default/sys_manifest_classpath/weblogic_patch.jar:/u01/app/oracle/middleware/java/jrockit-jdk1.6.0_45-R28.2.7-4.1.0/lib/tools.jar:/u01/app/oracle/middleware/11g/wlserver_10.3/server/lib/weblogic_sp.jar:/u01/app/oracle/middleware/11g/wlserver_10.3/server/lib/weblogic.jar:/u01/app/oracle/middleware/11g/modules/features/weblogic.server.modules_10.3.6.0.jar:/u01/app/oracle/middleware/11g/wlserver_10.3/server/lib/webservices.jar:/u01/app/oracle/middleware/11g/modules/org.apache.ant_1.7.1/lib/ant-all.jar:/u01/app/oracle/middleware/11g/modules/net.sf.antcontrib_1.1.0.0_1-0b2/lib/ant-contrib.jar::/u01/app/oracle/middleware/11g
    ++ ‘[' '!' -z '' ']‘
    ++ ‘[' '!' -z '' ']‘
    ++ export CLASSPATH
    ++ export PATH
    ++ cd /u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager
    ++ set -x
    ++ ‘[' '' '!=' '' ']‘
    ++ ‘[' start '!=' '' ']‘
    ++ /u01/app/oracle/middleware/java/jrockit-jdk1.6.0_45-R28.2.7-4.1.0/bin/java -jrockit -Xms128m -Xmx256m -Dcoherence.home=/u01/app/oracle/middleware/11g/coherence_3.7 -Dbea.home=/u01/app/oracle/middleware/11g -Xverify:none -Djava.security.policy=/u01/app/oracle/middleware/11g/wlserver_10.3/server/lib/weblogic.policy -Dweblogic.nodemanager.javaHome=/u01/app/oracle/middleware/java/jrockit-jdk1.6.0_45-R28.2.7-4.1.0 -DListenAddress=start weblogic.NodeManager -v

    Nov 1, 2013 4:17:57 PM weblogic.nodemanager.server.NMServerConfig initDomainsMap
    INFO: Loading domains file: /u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager/nodemanager.domains

    Nov 1, 2013 4:17:57 PM weblogic.nodemanager.server.NMServer
    INFO: Loaded node manager configuration properties from ‘/u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager/nodemanager.properties’
    Node manager v10.3

    Configuration settings:

    NodeManagerHome=/u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager
    ListenAddress=start
    ListenPort=5556
    ListenBacklog=50
    SecureListener=false
    AuthenticationEnabled=true
    NativeVersionEnabled=true
    CrashRecoveryEnabled=true
    JavaHome=/u01/app/oracle/middleware/java/jrockit-jdk1.6.0_45-R28.2.7-4.1.0/jre
    StartScriptEnabled=true
    StopScriptEnabled=false
    StartScriptName=startWebLogic.sh
    StopScriptName=
    LogFile=/u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager/nodemanager.log
    LogLevel=INFO
    LogLimit=0
    LogCount=1
    LogAppend=true
    LogToStderr=true
    LogFormatter=weblogic.nodemanager.server.LogFormatter
    DomainsFile=/u01/app/oracle/middleware/11g/wlserver_10.3/common/nodemanager/nodemanager.domains
    DomainsFileEnabled=true
    StateCheckInterval=500
    UseMACBroadcast=false
    DomainRegistrationEnabled=false
    DomainsDirRemoteSharingEnabled=false

    Domain name mappings:

    dwcc_domain -> /u01/app/oracle/domains/dwcc_domain

    Nov 1, 2013 4:17:58 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Startup configuration properties loaded from “/u01/app/oracle/domains/dwcc_domain/servers/IBR_server2/data/nodemanager/startup.properties”

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Resume monitoring of active server process (pid = 21402)

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Initializing ServerMonitor for weblogic.nodemanager.server.ServerManager@1e60fe07 : with config : weblogic.nodemanager.common.StartupConfig@1e6d111a

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Startup configuration properties loaded from “/u01/app/oracle/domains/dwcc_domain/servers/UCM_server2/data/nodemanager/startup.properties”

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Resume monitoring of active server process (pid = 26020)

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.AbstractServerManager log
    INFO: Initializing ServerMonitor for weblogic.nodemanager.server.ServerManager@1e6d262c : with config : weblogic.nodemanager.common.StartupConfig@1e6d39ac

    java.net.UnknownHostException: start
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:876)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1229)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1180)
    at java.net.InetAddress.getAllByName(InetAddress.java:1110)
    at java.net.InetAddress.getAllByName(InetAddress.java:1046)
    at java.net.InetAddress.getByName(InetAddress.java:996)
    at weblogic.nodemanager.server.Listener.(Listener.java:34)
    at weblogic.nodemanager.server.NMServer.start(NMServer.java:203)
    at weblogic.nodemanager.server.NMServer.main(NMServer.java:382)
    at weblogic.NodeManager.main(NodeManager.java:31)

    Nov 1, 2013 4:17:59 PM weblogic.nodemanager.server.NMServer main
    SEVERE: Fatal error in node manager server
    java.net.UnknownHostException: start
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:876)
    at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1229)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1180)
    at java.net.InetAddress.getAllByName(InetAddress.java:1110)
    at java.net.InetAddress.getAllByName(InetAddress.java:1046)
    at java.net.InetAddress.getByName(InetAddress.java:996)
    at weblogic.nodemanager.server.Listener.(Listener.java:34)
    at weblogic.nodemanager.server.NMServer.start(NMServer.java:203)
    at weblogic.nodemanager.server.NMServer.main(NMServer.java:382)
    at weblogic.NodeManager.main(NodeManager.java:31)

    Why?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>