So you’ve got Weblogic installed and running in a large server farm and you want to ease operations support by starting Weblogic on server boot. The Windows version of Weblogic comes with a script to install Node Manager as a system service, however in order to autostart Weblogic on linux, you must write your own init.d script.
Node Manager per Domain
One way to autostart Weblogic is to start Node Manager as a service, then write scripts to use Node Manager to start your admin server and any managed servers.
Prior to 12c, Node Manager by default was installed with the Weblogic install not with a Weblogic domain. So by default, the previous version of Node Manager was used to manage all domains on a given application host.
Now with Oracle Weblogic 12c, the default behavior is to have a single Node Manager instance per domain. You can revert back to the old way and have a single Node Manager per host however.
When you create a Weblogic domain in 12c, you will find Node Mananger to be installed under <DOMAIN_HOME>/nodemanager and its start scripts under <DOMAIN_HOME>/bin.
Sample Script for Autostarting Weblogic
The sample Node Manager service script below has been written to work with Oracle Weblogic 12c and supports Node Manager for a single domain. This script will autostart Weblogic for a specific domain.
Save this file as [domain_name]-nm and place it under /etc/init.d
Intentionally leave off the file extension. Do not add .sh to the script.
Make sure root owns this file and that its readable by everyone.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
#!/bin/sh # # chkconfig: 345 85 15 # description: per domain Oracle Weblogic Node Manager service init script ### BEGIN INIT INFO # Provides: jtest-dom1213-nodemanager # Required-Start: $network $local_fs # Required-Stop: # Should-Start: # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: per domain Oracle Weblogic Node Manager service. # Description: Starts and stops per domain Oracle Weblogic Node Manager. ### END INIT INFO . /etc/rc.d/init.d/functions #### BEGIN CUSTOM ENV DOMAIN_HOME="/u01/domains/veyron" MW_HOME=/u01/Oracle/Middleware/Oracle_Home JAVA_HOME=/usr/java/jdk1.7.0_79/ LD_LIBRARY_PATH=/u01/Oracle/Middleware/Oracle_Home/wlserver/server/native/linux/x86_64:/usr/lib:/lib:/usr/X11R6/lib #### END CUSTOM ENV PROCESS_STRING="^.*$DOMAIN_HOME.*weblogic.NodeManager.*" PROGRAM_START="$DOMAIN_HOME/bin/startNodeManager.sh" NODEMANAGER_DIR=$DOMAIN_HOME/nodemanager NODEMANAGER_LOCKFILE="$NODEMANAGER_DIR/nodemanager.log.lck" OUT_FILE="$NODEMANAGER_DIR/nodemanager.out" 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) !" echo exit fi echo -n $"Starting $SERVICE_NAME ... " echo "`date` Starting $SERVICE_NAME ... " > $OUT_FILE 2>&1 export MW_HOME export JAVA_HOME export LD_LIBRARY_PATH $PROGRAM_START >> $OUT_FILE 2>&1 & RETVAL=$? if [ $RETVAL -eq 0 ] ; then wait_for "socket listener started on port" else echo "FAILED: $RETVAL. Please check $OUT_FILE for more information." fi echo } wait_for() { res=$(cat "$OUT_FILE" | fgrep -c "$1") count=60 while [[ ! $res -gt 0 ]] && [[ $count -gt 0 ]] do sleep 1 count=$(($count - 1)) res=$(cat "$OUT_FILE" | fgrep -c "$1") done res=$(cat "$OUT_FILE" | fgrep -c "$1") if [ ! $res -gt 0 ]; then echo "FAILED or took too long time to start. Please check $OUT_FILE for more information." else echo "OK" touch $LOCKFILE fi } stop() { echo -n $"Stopping $SERVICE_NAME ... " OLDPID=`/usr/bin/pgrep -f $PROCESS_STRING` if [ "$OLDPID" != "" ]; then echo -n "(pid $OLDPID) " /bin/kill -TERM $OLDPID RETVAL=$? echo "OK" /bin/rm -f $NODEMANAGER_LOCKFILE [ $RETVAL -eq 0 ] && rm -f $LOCKFILE else /bin/echo "$SERVICE_NAME is stopped" fi echo } 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 echo RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" exit 1 esac exit $RETVAL |
Modify the Script
Before you can use this script, you must modify it to fit your environment. Locate the ### BEGIN CUSTOM ENV ### section of the script and modify the variables to match your environment.
The following variables will need to be updated:
1 2 3 4 5 6 |
#### BEGIN CUSTOM ENV DOMAIN_HOME="/u01/domains/veyron" MW_HOME=/u01/Oracle/Middleware/Oracle_Home JAVA_HOME=/usr/java/jdk1.7.0_79/ LD_LIBRARY_PATH=/u01/Oracle/Middleware/Oracle_Home/wlserver/server/native/linux/x86_64:/usr/lib:/lib:/usr/X11R6/lib #### END CUSTOM ENV |
Autostart Weblogic as the Weblogic Owner
By default init.d scripts are run and owned by root on your server. So you want this init.d Node Manager service to run Node Manager as the Weblogic domain owner, not root. If you run Node Manager as root, then root will end up owning files in your domain and that ends up creating problems and headaches.
The PROGRAM_START variable in the script specifies the command for starting Node Manager. We can simply use su to control who starts Node Manager:
su -c [command] [domain_owner]
For instance, if I have an OS user weblogic that owns the domain directory and all of its contents, I can use the following command to start Node Manager as weblogic.
su -c $DOMAIN_HOME/bin/startNodeManager.sh weblogic
So go ahead and modify the PROGRAM_START variable in the service script so that Node Manager is started by your domain owner.
Start Node Manager as a Service
Once you have modified the script to fit your environment, go ahead and add this new service as a system service using chkconfig. This will cause NM to be started each time on server boot.
chkconfig --add [domain_name]-nm
To manually start NM as a service, type:
service [domain_name]-nm start
The script you created will generate a stdout file under [DOMAIN_HOME]/nodemanager. Check this file for any error messages.