Wednesday, June 21, 2017

emctl Missing on OEM / emctl utility corrupted / removed on 12c/13c


emctl Missing on OEM / emctl utility corrupted / removed



Recreate the emctl Script for the Enterprise Manager OMS/Agent (Doc ID 1404623.1)


Problem

Enterprise Manager Base Platform - Version 12.1.0.1.0 and later

My agent emctl script got corrupted or accidently removed and able to execute the via emctl.  Then how would I restore / repair the emctl script.

approach

Copy the emctl.template to emctl at same location in Agent Home or OMS Home, where you have missed the file.

Here in my case I got missed in Agent Home

[oracle@oem250 bin]$ cd  /u01/app/oracle/Agent12c/core/12.1.0.5.0/bin
[oracle@oem250 bin]$ ls -lthra emctl*
-rw-r--r-- 1 oracle oinstall 18K Mar  8  2015 emctl.template.ouibak
-rwx------ 1 oracle oinstall 18K Mar  8  2015 emctl.template
-rwx------ 1 oracle oinstall 22K Jun 11  2015 emctl.pl.ouibak
-rwxr--r-- 1 oracle oinstall 18K Jun 11  2015 emctl.ouibak
-rwx------ 1 oracle oinstall 22K Oct 21 00:15 emctl.pl
-rw-r--r-- 1 oracle oinstall 18K Oct 26 04:40 emctl_old
-rwxr--r-- 1 oracle oinstall 18K Oct 26 04:40 emctl_old_21Jun2017
-rwx--x--x 1 oracle oinstall 18K Oct 28 11:35 emctl


 [oracle@oem250 bin]$ ls -ltrah emctl.template
-rwx------ 1 oracle oinstall 18K Mar  8  2015 emctl.template

[oracle@oem250 bin]$ cp emctl.template emctl
[oracle@oem250 bin]$ vi emctl

Change the below parameter in emctl script.

# Allow environment setting of CONSOLE_CFG to be used if already set
CONSOLE_CFG=agent

# Emctl for an Agent can be configured to be for PAAS agent or (default NONE).
EMCTLCFG_MODE=NONE

#No more overriding of EMDROOT through the environment - see bug 3217672
#Instead, allow overriding through REMOTE_EMDROOT variable for state only
#installs
if [ "$REMOTE_EMDROOT" = "" ];
then
  ORACLE_HOME=/u01/app/oracle/Agent12c/core/12.1.0.5.0
  EMDROOT=/u01/app/oracle/Agent12c/core/12.1.0.5.0

  #DEFAULT_EMSTATE=/u01/app/oracle/Agent12c/agent_inst
  export DEFAULT_EMSTATE


#Fix for bug 16304030. Change the CRS_HOME setting if modified.
if [ "$CRS_HOME" = "" ]; then
 CRS_HOME=
fi

#This is the location of setuid executables at the agent
SBINDIR=/u01/app/oracle/Agent12c/sbin

#Values for HOST_SID_OFFSET_ENABLED : "" (unset), "host_sid", "host_only"
HOST_SID_OFFSET_ENABLED=


Below are emctl script which created from existing template on OEM and changes parameter accordingly.

[oracle@oem250 bin]$ pwd
/u01/app/oracle/Agent12c/core/12.1.0.5.0/bin

[oracle@oem250 bin]$ more emctl
#!/bin/sh -f
#++
#  emctl - control script for webapp operations
#
#  emctl is used to start and stop the oc4j servlet container
#  with the SMP Webapplications that provide monitoring and admin-
#  istration capabilities.
#--
#
# MODIFIED
.......................
.......................
.......................
.......................to be contd..

EMCTL_ENV_FILE=
if [ "$EMCTL_DEBUG" != "" ] ; then
    EMCTL_PID=$$
    EMCTL_ENV_FILE_DIR=/tmp
    EMCTL_ENV_FILE=${EMCTL_ENV_FILE_DIR}/emctl.env.$EMCTL_PID
    export EMCTL_ENV_FILE
    env | sort > $EMCTL_ENV_FILE
fi

# Allow environment setting of CONSOLE_CFG to be used if already set

CONSOLE_CFG=agent     ### if oms then change to ==>  central

if [ "$CONSOLE_CFG" = "" -o "$CONSOLE_CFG" = "agent" ];
then
  ISAGENT_CFG="y"
else
  ISAGENT_CFG="n"
fi

# Emctl for an Agent can be configured to be for PAAS agent or (default NONE).
EMCTLCFG_MODE=none

POUND_SYM="#"
INVALID_EMDROOT="${POUND_SYM}EMDROOT${POUND_SYM}"

#No more overriding of EMDROOT through the environment - see bug 3217672
#Instead, allow overriding through REMOTE_EMDROOT variable for state only
#installs
if [ "$REMOTE_EMDROOT" = "" ];
then
  ORACLE_HOME=/u01/app/oracle/Agent12c/core/12.1.0.5.0
  EMDROOT=/u01/app/oracle/Agent12c/core/12.1.0.5.0
  if [ "$ISAGENT_CFG" = "n"  -o "$EMDROOT" = "" -o $EMDROOT = $INVALID_EMDROOT ];
  then
    EMDROOT=$ORACLE_HOME
  fi
else
  ORACLE_HOME=$REMOTE_EMDROOT
  if [ "$ISAGENT_CFG" = "n" -o "$REMOTE_EMDROOT_AGHOME" = "" ];
  then
    EMDROOT=$ORACLE_HOME
  else
    EMDROOT=$REMOTE_EMDROOT_AGHOME
  fi
  export REMOTE_EMDROOT
  export REMOTE_EMDROOT_AGHOME
fi

if [ "$ISAGENT_CFG" = "y" ];
then
 # DEFAULT_EMSTATE=/u01/app/oracle/Agent12c/agent_inst
  export DEFAULT_EMSTATE
fi

if [ "$CONSOLE_CFG" = "core" -o "$CONSOLE_CFG" = "central" ]; then
    # Make sure certain environment variables are set
    # for OMS
    MW_HOME=`cd "$ORACLE_HOME/.." ; pwd`
    if [ -d "$MW_HOME" ]; then
        export MW_HOME

        # Set the home directories...
        if [ -x "$ORACLE_HOME/common/bin/setHomeDirs.sh" ]; then
            . "$ORACLE_HOME/common/bin/setHomeDirs.sh"
        elif [ -x "$MW_HOME/oracle_common/common/bin/setHomeDirs.sh" ]; then
            . "$MW_HOME/oracle_common/common/bin/setHomeDirs.sh"
        fi

        # Set the environment ...
        if [ "${WL_HOME}" != "" ]; then
            if [ -x "${WL_HOME}/common/bin/commEnv.sh" ]; then
                . "${WL_HOME}/common/bin/commEnv.sh"
            fi
        fi
    fi

    #Set JAVA_HOME to the one provided by installenv.sh
    if [ -x "${ORACLE_HOME}/install/scripts/installenv.sh" ] ; then
       . "${ORACLE_HOME}/install/scripts/installenv.sh"
    fi

else
  JAVA_HOME=$ORACLE_HOME/jdk
fi

JRE_HOME=$ORACLE_HOME#JRE_EXTDIR#
PERL_BIN=$ORACLE_HOME/perl/bin
PERL_HOME=$ORACLE_HOME/perl
EM_STANDALONE=#EM_STANDALONE#    

#Fix for bug 16304030. Change the CRS_HOME setting if modified.
if [ "$CRS_HOME" = "" ]; then
 CRS_HOME=
fi

#This is the location of setuid executables at the agent
SBINDIR=/u01/app/oracle/Agent12c/sbin

#Values for HOST_SID_OFFSET_ENABLED : "" (unset), "host_sid", "host_only"
HOST_SID_OFFSET_ENABLED=

#Unset LD_ASSUME_KERNEL: Only used for LinuxThreads model (old)
if [ "$LD_ASSUME_KERNEL" != "" -a "X$EMAGENT_FORCE_LDASSUME" =  "X" ]
then
unset LD_ASSUME_KERNEL
fi

#Unset ORA_NLS*
ALL_ORA_NLS_ENV=`env | grep ORA_NLS`
for oranlsenv in ${ALL_ORA_NLS_ENV}
do
 unset `echo $oranlsenv | cut -d= -f1`
done

#Unset ORA_TZFILE - Fix for bug#13739688.

if [ "$ORA_TZFILE" != "" ]
then
unset ORA_TZFILE
fi

export JAVA_HOME
export JRE_HOME
export ORACLE_HOME
export EMDROOT
export CONSOLE_CFG
export PERL_BIN
export PERL_HOME
export EM_STANDALONE
export CRS_HOME
export SBINDIR
export HOST_SID_OFFSET_ENABLED
export EMCTLCFG_MODE

#Source commonenv settings
if [ -f $ORACLE_HOME/bin/commonenv ]; then
. $ORACLE_HOME/bin/commonenv
fi

EM_OC4J_HOME=#EM_OC4J_HOME#
export EM_OC4J_HOME

OUILOC=$ORACLE_HOME/oui

# these variables - PERL5LIB and LD_LIBRARY_PATH - are set so that
# osfetchlets can run correctly

uname=`uname`
hardware=`uname -m`

PERL5LIB_NATIVE=$ORACLE_HOME/perl/lib:$ORACLE_HOME/perl/lib/site_perl
PERL5LIB_TMP=${PERL5LIB_NATIVE}:$ORACLE_HOME/perl/libwww-perl/lib:$ORACLE_HOME/perl/ext/POSIX:$ORACLE_HOME/perl/URI:$ORACLE_HOME/perl/HTML_Parser:$ORACLE_HOME/perl/HTML
-Parser/lib:$EMDROOT/sysman/admin/scripts:$EMDROOT/bin:$ORACLE_HOME/bin:$EMDROOT/sysman/admin/scripts/Net-DNS-0.48/lib/:$EMDROOT/sysman/admin/scripts/libnet-1.19/

if [ "$PERL5LIB" = "" ] ;
then
   PERL5LIB=${PERL5LIB_TMP}
else
   PERL5LIB=${PERL5LIB_TMP}:${PERL5LIB}
fi

# >>> EMDROOT is always the same as ORACLE_HOME in this script.
# >>> Therefore I am removing the duplicate entries below.
# >>> (E.g., We don't need $ORACLE_HOME/lib and $EMDROOT/lib in the paths.)
# Starting 11.2 EMDROOT may not necessarily be the same.
# We need to make sure EMDROOT/... also appears in the path
if [ "$EMDROOT" = "$ORACLE_HOME" ];
then
  AGENT_LIB_PATH=$EMDROOT/instantclient:$ORACLE_HOME/lib
  AGENT_LIB32_PATH=$ORACLE_HOME/lib32
  AGENT_LIB64_PATH=$ORACLE_HOME/lib64
  AGENT_BIN_PATH=$ORACLE_HOME/bin
else
  AGENT_LIB_PATH=$EMDROOT/instantclient:$ORACLE_HOME/lib:$EMDROOT/lib
  AGENT_LIB32_PATH=$ORACLE_HOME/lib32:$EMDROOT/lib32
  AGENT_LIB64_PATH=$ORACLE_HOME/lib64:$EMDROOT/lib64
  AGENT_BIN_PATH=$ORACLE_HOME/bin:$EMDROOT/bin
fi

if [ "$LD_LIBRARY_PATH" = "" ] ; then
   LD_LIBRARY_PATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#
else
   LD_LIBRARY_PATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#:$LD_LIBRARY_PATH
fi

#############################
# On Solaris, the 64bit JVM does the following to compute LD_LIBRARY_PATH:
# 1.  Prepend JDK and JRE specific lib paths
# 2.  Append LD_LIBRARY_PATH only if LD_LIBRARY_PATH_64 is not defined.
#     If LD_LIBRARY_PATH_64 is defined, it ignores existing LD_LIBRARY_PATH and appends LD_LIBRARY_PATH_64 to it.
#     It also clears LD_LIBRARY_PATH_64 from the environment.
# Note: In JDK7, if they change the logic for computing and setting LD_LIBRARY_PATH changes then we will have
# to re-evaluate this fix.
#
# So emctl on Solaris will do the following:
# If LD_LIBRARY_PATH_64 is not defined in the environment, emctl will not export the variable.
# If LD_LIBRARY_PATH_64 is defined in the environment, emctl will export the value as before.  The JVM on Solaris
# will ensure that LD_LIBRARY_PATH is computed as indicated above.
#############################

EXPORT_LD_LIBRARY_PATH_64="YES"
if [ "$LD_LIBRARY_PATH_64" = "" ] ; then
   LD_LIBRARY_PATH_64=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#
   if [ "$uname" = "SunOS" ];
   then
     EXPORT_LD_LIBRARY_PATH_64="NO"
   fi
else
   LD_LIBRARY_PATH_64=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#:$LD_LIBRARY_PATH_64
fi

if [ "$SHLIB_PATH" = "" ] ; then
   SHLIB_PATH=$ORACLE_HOME/perl/lib:$AGENT_LIB_PATH:$AGENT_LIB32_PATH:$OUILOC/lib/#PLATFORM#:$AGENT_LIB64_PATH
else
   SHLIB_PATH=$ORACLE_HOME/perl/lib:$AGENT_LIB_PATH:$AGENT_LIB32_PATH:$OUILOC/lib/#PLATFORM#:$SHLIB_PATH:$AGENT_LIB64_PATH
fi

if [ "$LIBPATH" = "" ] ; then
   LIBPATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$AGENT_LIB32_PATH:$OUILOC/lib/#PLATFORM#
else
   LIBPATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$AGENT_LIB32_PATH:$OUILOC/lib/#PLATFORM#:$LIBPATH
fi

if [ "$DYLD_LIBRARY_PATH" = "" ] ; then
   DYLD_LIBRARY_PATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#
else
   DYLD_LIBRARY_PATH=$AGENT_LIB_PATH:$ORACLE_HOME/perl/lib:$OUILOC/lib/#PLATFORM#:$DYLD_LIBRARY_PATH
fi

# 7319281: Add JAVA_RTLINK_PATH from s_emagent.mk just in case we miss a platform
LD_LIBRARY_PATH=$JAVA_RTLINK_PATH:$LD_LIBRARY_PATH
SHLIB_PATH=$JAVA_RTLINK_PATH:$SHLIB_PATH
DYLD_LIBRARY_PATH=$JAVA_RTLINK_PATH:$DYLD_LIBRARY_PATH
LIBPATH=$JAVA_RTLINK_PATH:$LIBPATH

# to workaround Solaris2.8 Java thr_suspend hang, use alternate libthread.
# Since this directory doesn't exist on other versions, this is a noop there.
#
if [ "$uname" = "SunOS" ];
then
        LD_LIBRARY_PATH=/usr/lib/lwp:$LD_LIBRARY_PATH
fi

# export copies of LD_LIBRARY_PATH, LIBPATH, SHLIB_PATH, and PERL5LIB
# so that nmo and nmosudo can reinstate them (bugs 5173504, 6742459)
LD_LIBRARY_PATH_SNMO=${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH_SNMO

LIBPATH_SNMO=${LIBPATH}
export LIBPATH_SNMO

# versions of these paths for export to nmosudo *must* begin with SNMO.
# sudo's default behavior is to remove *any* environment variable beginning
# with "LD_", "DYLD_", etc.
SNMO_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
export SNMO_LD_LIBRARY_PATH

SNMO_SHLIB_PATH=${SHLIB_PATH}
export SNMO_SHLIB_PATH

SNMO_DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}
export SNMO_DYLD_LIBRARY_PATH

SNMO_PERL5LIB=${PERL5LIB}
export SNMO_PERL5LIB

export PERL5LIB
export LD_LIBRARY_PATH
if [ "$EXPORT_LD_LIBRARY_PATH_64" = "YES" ]
then
  export LD_LIBRARY_PATH_64
fi
export SHLIB_PATH
export LIBPATH
export DYLD_LIBRARY_PATH

# Add the var for HP
if [ "$uname" = "HP-UX" ] ; then
   UNIX95=XPG4;
   export UNIX95
   # fix for emctl stop issue on HP.
   EM_OC4J_OPTS="-d64 -XX:MaxPermSize=1024m -XdoCloseWithReadPending $EM_OC4J_OPTS"
   export EM_OC4J_OPTS
fi

#
# Set path so that our native executables can be found when run from java
#
PATH=$AGENT_BIN_PATH:$ORACLE_HOME/jdk/bin:$PERL_BIN:$PATH:/bin:/usr/bin
export PATH

#
# Set up DEFAULT_CLASSPATH, needed by the Secure perl modules to locate
# dependent jars for command line calls to java
#
DEFAULT_CLASSPATH=$ORACLE_HOME/jdbc/lib/ojdbc14.jar:$ORACLE_HOME/oc4j/jdbc/lib/ojdbc14dms.jar:$ORACLE_HOME/oc4j/lib/dms.jar:$ORACLE_HOME/oc4j/jdbc/lib/orai18n.jar:$ORAC
LE_HOME/jlib/uix2.jar:$EMDROOT/sysman/jlib/emCORE.jar:$EMDROOT/sysman/jlib/emcoreAgent.jar:$EMDROOT/sysman/jlib/emagentSDK.jar:$ORACLE_HOME/xdk/lib/xmlparserv2.jar:$EMD
ROOT/sysman/jlib/log4j-core.jar:$ORACLE_HOME/j2ee/OC4J_EM/applications/em/em/WEB-INF/lib/ojpse_2_1_5.jar:$ORACLE_HOME/j2ee/home/lib/http_client.jar:$ORACLE_HOME/oc4j/j2
ee/home/lib/http_client.jar:$EMDROOT/modules/oracle.http_client_11.1.1.jar:$ORACLE_HOME/../oracle_common/modules/oracle.http_client_11.1.1.jar:$ORACLE_HOME/sysman/webap
ps/emd/WEB-INF/lib/ojpse_2_1_5.jar
export DEFAULT_CLASSPATH

# use ulimit to make sure we have enough descriptors

MIN_EM_DESCRIPTORS_RECOMMENDED=4096
if [ "$EM_DESCRIPTORS" = "" ] || [ $EM_DESCRIPTORS -lt $MIN_EM_DESCRIPTORS_RECOMMENDED ]
then
   EM_DESCRIPTORS=$MIN_EM_DESCRIPTORS_RECOMMENDED
fi

CURRENT_LIMIT=`ulimit -n`

if [ "$CURRENT_LIMIT" != "unlimited" ]
then
   if [ $CURRENT_LIMIT -lt $EM_DESCRIPTORS ]
   then
      ulimit -n $EM_DESCRIPTORS
   fi
fi

if [ "$EMCTL_DEBUG" != "" ] ; then
    echo emctl: launching $PERL_BIN/perl $EMDROOT/bin/emctl.pl "$@"
fi

if [ "$EMCTL_DEBUG" != "" ] ; then
   env | sort > ${EMCTL_ENV_FILE}.2
   diff ${EMCTL_ENV_FILE} ${EMCTL_ENV_FILE}.2 > ${EMCTL_ENV_FILE}.diff
   echo Env changes in emctl recorded in ${EMCTL_ENV_FILE}.diff
   rm ${EMCTL_ENV_FILE}.2
fi

# Execute the emctl.pl
$PERL_BIN/perl $ORACLE_HOME/bin/emctl.pl "$@"

cmdexitcode=$?

if [ "$EMCTL_DEBUG" != "" ] ; then
    rm $EMCTL_ENV_FILE
fi

exit $cmdexitcode



Now emctl script is ready for testing as per current environment..

1 comment: