Scripting WebLogic Admin Server Startup
By Antony Reynolds-Oracle on Apr 25, 2012
How to Script WebLogic Admin Server Startup
My first car was a 14 year old Vauxhall Viva. It is the only one of my cars that has ever been stolen, and to this day how they stole it is a mystery to me as I could never get it to start. I always parked it pointing down a steep hill so that I was ready to jump start it! Of course its ability to start was dramatically improved when I replaced the carburetor butterfly valve!
Getting SOA Suite or other WebLogic based systems to start can sometimes be a problem because the default WebLogic start scripts require you to stay logged on to the computer where you started the script. Obviously this is awkward and a better approach is to run the script in the background. This problem can be avoided by using a WLST script to start the AdminServer but that is more work, so I never bother with it.
If you just run the startup script in the background the standard output and standard error still go to the session where you started the script, not helpful if you log off and later want to see what is happening. So the next thing to do is to redirect standard out and standard error from the script.
Finally it would be nice to have a record of the output of the last few runs of the Admin Server, but these should be purged to avoid filling up the directory.
Doing the above three tasks is the job of the script I use to start WebLogic. The script is shown below:
# SET VARIABLES
# MOVE EXISTING LOG FILE
logrotate -f -s $SCRIPT_HOME/logrotate.status $SCRIPT_HOME/AdminServerLogRotation.cfg
#RUN ADMIN SERVER
nohup $DOMAIN_HOME/startWebLogic.sh &> $LOG_FILE &
tail -f $LOG_FILE
Lets walk through each section of the script.
The first few lines of the script just set the environment. Note that I put the output of the start script into the same location and same filename that it would go to if I used the Node Manager to start the server. This keeps it consistent with other servers that are started by the node manager.
MOVE EXISTING LOG FILE
The next section keeps a copy of the previous output file by using the logrotate command. This reads its configuration from the “AdminServerLogRotation.cfg” file shown below:
This tells the logrotate command to keep 10 copies (rotate 10) of the log file and if there is no previous copy of the log file that is not an error condition (missingok).
The logrotate.status file is used by logrotate to keep track of what it has done. It is ignored when the –f flag is used, causing the log file to be rotated every time the command is invoked.
RUN ADMIN SERVER
UPDATE: Sometimes the tail command starts before the shell has created the log file for the startWebLogic.sh command. To avoid an error in the tail command I "touch" the log file to make sure that it is there.
The final section actually invokes the standard command to start an admin server (startWebLogic.sh) and redirects the standard out and standard error to the log file. Note that I run the command in the background and set it to ignore the death of the parent shell.
Finally I tail the log file so that the user experience is the same as running the start command directly. However in this case if I Ctrl-C the command only the tail will be terminated, the Admin Server will continue to run as a background process.
This approach allows me to watch the output of the AdminServer but not to shut it down if I accidently hit Ctrl-C or close the shell window.
I also have a restart script shown below:
# SET VARIABLES
# STOP ADMIN SERVER
# RUN ADMIN SERVER
This is just like the start script except that it runs the stop weblogic command followed by my start script command.
The above scripts are quick and easy to put in place for the Admin Server and make the stdout and stderr logging consistent with other servers that are started from the node manager. Now can someone help me push start my car!