11 Dec

Use Autoconfig for common system administrator tasks

Use Autoconfig for common system administrator tasks

Autoconfig is a wonderful tool that may be extended and customized to meet a variety of needs.  One mundane task I don’t deal with anymore is scripting certain basic operating system scripts.  For example:

  • Rotating logs
  • Cleaning out old trace files
  • Init scripts

… are all examples of cron jobs and scripts that must be created post-install.  Many DBAs have a set of scripts they use and modify, but why not use an autoconfig template to generate what you need every time?

I’ll use an init script as an example.  Oracle provides adstrtal.sh and adstpall.sh for starting and stopping an apps environment; however neither of those scripts are ready to run out of /etc/init.d for system startup and shutdown.

Below is an Autoconfig template that will generate an init.d script that will call both adstrtal.sh and adstpall.sh on system startup and shutdown, respectively.  The script is designed for a RedHat Linux variant like RHEL, OEL, or CentOS.  The application version was 12.1.1.

#!/bin/bash

# %s_dbSid% 	Start script for the vis applications
#
# chkconfig:  -	85 15
# description:  %s_dbSid% is an oracle applications instance

# Must be root
[ $USER != "root" ] && echo "User must be root" && exit 1

# source functions
. /etc/rc.d/init.d/functions

prog=app%s_dbSid%
appstop=%s_config_home%/admin/scripts/adstpall.sh
appstart=%s_config_home%/admin/scripts/adstrtal.sh
mgrctl=%s_config_home%/admin/scripts/adcmctl.sh
appuser=%s_appsuser%
appgroup=%s_appsgroup%
appssys=%s_apps_user%
logdir=/var/log/oa
logfile=app%s_dbSid%

LOG=$logdir/$logfile
USAGE="$prog: [start|stop|abort]"
RETVAL=0

if [ $# -lt 1 ]; then
   echo $USAGE
   exit 1
fi

if [ ! -d $logdir ]; then
   mkdir -p $logdir
   touch $LOG
   chgrp -R $appgroup $logdir
   chmod g+r $logdir
fi

# Define some functions

exit_error() {
   RETVAL=$1
   message="$2"
   echo "$message"
   echo_failure
   echo
   exit $RETVAL
}

get_appspass() {
# Substitute a better password retrieval function
   SECRET=/home/$appuser/.secret
   appspass=`grep ^%s_apps_user%= $SECRET | awk -F"=" '{print $2}'` 2>>$LOG
   [ $? -ne 0 ] && echo "Could not find %s_apps_user% password - exiting" >>$LOG 2>&1 && exit 1
   CONNECT="%s_apps_user%/$appspass"
}

# Start the applications
start() {
   echo -n $"Starting $prog: "
   get_appspass
   su - $appuser -c "$appstart $CONNECT" >>$LOG 2>&1
   RETVAL=$?
   return $RETVAL
}

# Stop the applications
stop() {
   echo -n $"Stopping $prog: "
   get_appspass
   su - $appuser -c "$appstop $CONNECT" >>$LOG 2>&1
   RETVAL=$?
   return $RETVAL
}

# Stop the applications and abort the concurrent managers (faster)
abort() {
   echo -n $"Aborting $prog: "
   get_appspass
   su - $appuser -c "$mgrctl abort $CONNECT" #| tee >>$LOG 2>&1
   su - $appuser -c "$appstop $CONNECT" #| tee >>$LOG 2>&1
   RETVAL=$?
   return $RETVAL
}

# Main program

mode=$1

case $mode in
   start)
      start
      ;;
   stop)
      stop
      ;;
   abort)
      abort
      ;;
   *)
      echo $USAGE
      exit 1
esac

if [ $RETVAL -eq 0 ]; then
   echo_success
else
   echo_failure
fi
echo

exit $RETVAL

To install this script, all I need to do is the following:

Place the script in a template file in my custom application top.

Create a driver that will create the script; I usually create a /tools directory for this sort of thing.

Run autoconfig to create the script.

As root, copy the script to /etc/init.d

Use chkconfig to enable auto start/stop on system boot:

$ chkconfig –-add
$ chkconfig on

That’s it!  Now every time I create a clone, I have a new init script for that node.  If a path or other dependent context value changes, I simply copy the updated script into /etc/init.d and follow the steps above.

I should note that with this script specifically, because it requires the apps password, you should probably find a better way to store and retrieve the apps password.  In this example, I put it in a file called /home/appl/.secret, which had permission bits set to 660.  That’s an “OK” solution, but not great.  The script grabs the password using a function specifically to allow minimal fuss and muss when updating the password storage and retrieval method.

Anyway, it’s pretty easy to see how one could leverage Autoconfig to create simple time-saving scripts because Autoconfig already “knows” where everything is.

Here’s an example of a script to clean up concurrent manager log and output:

#!/bin/sh

env_file="%s_applfenv%"

if [ ! -f $env_file ];
then
   printf "Cannot find environment file $env_file\n"
   printf "ERRORCODE = 1 ERRORCODE_END\n"
   exit 1
else
   . $env_file
fi

# Clean up concurrent manager log and output directories
/usr/bin/find $APPLCSF/$APPLOUT -name "*.out" -ctime \
   +%c_conc_out_ret% | xargs rm -rf
/usr/bin/find $APPLCSF/$APPLLOG -name "*.req" -ctime \
   +%c_conc_log_ret% | xargs rm -rf

# Clean up the instance logs
/usr/bin/find $INST_TOP/admin/log -type d -ctime \
   +%c_inst_log_ret% | xargs rm –rf;

exit $?

In this example, I created 3 custom context variables:

c_conc_out_ret
c_conc_log_ret
c_inst_log_ret

Each are set to the retention period in days for their respective logs.

Installation for a script like this is even more hands-off than an init script.  Typically log cleanup scripts are called from cron and are often registered as individual crontab commands.  For this script, a single crontab entry could point to the absolute location of the script.  If the value of an environment or context variable changed at any time, running Autoconfig would automatically update the scheduled job.

Operating system maintenance plays a critical role in a well-organized, automated Apps environment; the less manual scripting there is, the less likely it is to be skipped.

Related posts from the blog:

  1. Metalink wget download script
    Looking for a simpler way to download from the new Metalink?  Oracle has replaced the ftp site with...
  2. FNDCPASS doesn’t always use the SYSTEM password
    FNDCPASS does not check the system password when used to change an applications user account. We can check...
  3. 6 things to do after an Oracle Apps R12 install
    OK, so there are a ton of things to do right after a fresh R12 install.  And before...
  4. EC2 persistent boots with pivot root
    Amazon recently allowed Elastic Block Store to boot persistent images. However, there are two concerns I have with...
  5. New whitepaper: Common Oracle Misconceptions
    The consequence of large numbers of Oracle professionals taking advice without understanding it has been a great profusion...

No comments yet

Leave a Reply