My Services WebSphere Training | JEE Build & Deploy | Automatic Linux Provisioning
Here are some basic scripts that can help with Log Rolling, there are several ways this can be approached, this is one simple solution.
The JACL script is used to automate WebSphere settings, and I will port this to Jython at sometime in the near future.
The properties file is used to show how you can set the JACLscript.
The shell script is designed to be run by CRON and essentially archives current logs.Depending on how you set your WebSphere rolling policy will determine how you adjust these scripts to work together.
Note: you can also log into the WebSphere Administrative console and manually change log settings for a a JVM. Also note that working with WebSphere ND means you will have to roll-over log multiple nodes.
1. JACL Script to set Log Settings in WebSphere
#-------------------------------------------------------------- # load input.props file #-------------------------------------------------------------- proc loadProperties {propFileName} { java::import java.io.FileInputStream java::import java.util.Properties set fileprop [java::new Properties] set fileStream [java::new FileInputStream $propFileName] $fileprop load $fileStream return $fileprop } set props [loadProperties logging_service.props] #--------------------------------------------------------------------------------- # This function sets the General properties of Logging and Tracing for the server. # Application servers > server > Logging and Tracing > JVM Logs #--------------------------------------------------------------------------------- proc setLoggingService { serverName serverIndex } { #-------------------------------------------------------------- # set up globals #-------------------------------------------------------------- global AdminConfig global AdminControl global AdminApp global props #-------------------------------------------------------------- # Setting the size variable #-------------------------------------------------------------- set rolloverType [$props getProperty com.server$serverIndex.LoggingService.rolloverType] set baseHour [$props getProperty com.server$serverIndex.LoggingService.baseHour] set rolloverPeriod [$props getProperty com.server$serverIndex.LoggingService.rolloverPeriod] set maxNumberOfBackupFiles [$props getProperty com.server$serverIndex.LoggingService.maxNumberOfBackupFiles] set s1 [list rolloverType $rolloverType] set s2 [list baseHour $baseHour] set s3 [list rolloverPeriod $rolloverPeriod] set s4 [list maxNumberOfBackupFiles $maxNumberOfBackupFiles] set paramList [list $s1 $s2 $s3 $s4] puts "SetLoggingService: Setting the Logging Service to $paramList" #-------------------------------------------------------------- # Change the size - Server1Name #-------------------------------------------------------------- set serverID [$AdminConfig getid /Server:$serverName/] set LoggingServiceList [$AdminConfig list StreamRedirect $serverID] foreach LoggingService $LoggingServiceList { $AdminConfig modify $LoggingService $paramList } $AdminConfig save puts "SetLoggingService: Done..." } #----------------------------------------------------------------- # Main loop thru each and every server to change the values #----------------------------------------------------------------- for {set serverIndex 1} {[string length [set serverName [$props getProperty com.server$serverIndex.name]]] != 0} {incr serverIndex} { puts "------------------------------------------------" puts "Info:- changing values for server : $serverName" puts "------------------------------------------------" set server $serverName set serverID [$AdminConfig getid /Server:$serverName/] if {[llength $serverID] == 0} { puts "Error: -- Server '/Server:$serverName/' not found" } else { puts "Success: -- Server ID '$serverID' found" # set the Logging Service related tuning parameters setLoggingService $server $serverIndex } }
1.1.
Sample Properties file that can extend the JACLScript.
#------------------------------------ # node releated settings Profile settings #------------------------------------ com.app.was.node1.name=was61cell1_node01 #com.app.was.node2.name=was61cell1_node02 #------------------------------------ # server related parameter #------------------------------------ #---------------------------------- # Server 1 #--------------------------------- com.server1.name=Server1 com.server1.LoggingService.rolloverType=TIME com.server1.LoggingService.baseHour=1 com.server1.LoggingService.rolloverPeriod=24 com.server1.LoggingService.maxNumberOfBackupFiles=14
2. Sample Shell script that can be run by cron #!/bin/sh # Websphere log rolling script for Linux,needs to be tested on other Linux Platforms # Author: Steve Robinson - WebsphereTools.com #Variables LOG_DIR='/var/apps/was61/node6101/profiles/logs/server1' ARCHIVE_LOG_DIR='/var/apps/was61/node6101/profiles/logs/server1/archive' LOG_FILES='SystemOut.log SystemErr.log' ARCHIVE_LOGS=`find $ARCHIVE_LOG_DIR/*.gz -mtime +14 -print` DATE_EXT=`/bin/date +"%b%d%Y"` GZIP='/bin/gzip' #Verify $ARCHIVE_LOG_DIR backup directory exists check_archive_log_dir () { if ! test -d $ARCHIVE_LOG_DIR; then echo "$ARCHIVE_LOG_DIR does not exist. Creating ${ARCHIVE_LOG_DIR}." mkdir $ARCHIVE_LOG_DIR if [ $? -ne 0 ]; then echo "$ARCHIVE_LOG_DIR could not be created." return 1 else chmod 755 ${ARCHIVE_LOG_DIR} fi else if ! test -w $ARCHIVE_LOG_DIR; then echo "${WHOAMI} does not have enough permissions to write to $ARCHIVE_LOG_DIR." return 1 fi fi return 0 } #Log Roller roll_logs () { for x in $LOG_FILES do cp -p ${LOG_DIR}/$x ${ARCHIVE_LOG_DIR}/$x.${DATE_EXT} if [ $? -ne 0 ]; then echo "Cannot copy file: ${LOG_DIR}/$x to a back up version." echo "Check for filesystem space ...!" return 1 else ${GZIP} -9 -q ${ARCHIVE_LOG_DIR}/$x.${DATE_EXT} if [ $? -ne 0 ]; then echo "Failed to compress file ${ARCHIVE_LOG_DIR}/$x.${DATE_EXT}, " echo "Check for filesystem space ...!" return 1 fi fi cat /dev/null > ${LOG_DIR}/$x done return 0 } #Remove $ARCHIVE_LOGS - Default is 14 days remove_logs () { for y in $ARCHIVE_LOGS do rm $y done } #Main Loop check_archive_log_dir roll_logs remove_logs
3. Example Cron Tab
* 0 * * * /home/was/lwas_ogroll.sh > /dev/null 2>&1
Steve Robinson has been working in IT for over 15 years and has provided solutions for many large-enterprise corporate companies across the world. Steve specialises in Java and Middleware consulting. Steve comes from both an administration and development background.
Before moving to JEE, Steve was an accomplished developer and consultant for both IBM Lotus Notes and Microsoft .NET Technologies.
Follow Steve as @stevencrobinson on twitter.
IBM WebSphere Application Server 8.0 Administration Guide
WebSphere Application Server 7.0 Administration Guide