8 Replies Latest reply on Jul 22, 2013 4:03 PM by Bill Robinson

    Bug or error with out of the box blasadmin script (with fix)

    Yanick Girouard

      My team has found two bugs or errors in the the out of the box blasadmin script that comes with BSA 8.1 on Linux and wrote a fix. I thought I'd share it with the community since it could still be present in later versions (to be confirmed).

       

      The first issue is that the PATH variable is wrongly set. The out of the box version precedes the app server path to the system path. This means that any os command used that also exists in NSH will be pointing to the NSH version instead of the system's version, which is not the desired behavior. The out of the box version also doesn't check if the app server path is already included in the $PATH variable before appending it, which could cause duplicates. Even though only the first one matches, this is bad practice.

       

      The fix for this is to append (and not "prepend") the app server paths to the system's path, and to use a function to only append if it's not already present. Such as this:

       

      pathadd() {

          if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then

              PATH="${PATH:+"$PATH:"}$1"

          fi

      }

       

      pathadd /opt/bladelogic/appserver/NSH/bin

      pathadd /opt/bladelogic/appserver/NSH/sbin

       

      The second is that there's a chown -R at the end of the script that resets the ownership of the whole deployments directory after any blasadmin command is called. This is required because the create command would otherwise create deployments as root instead of bladmin (when called with root), but it's not the right way to do it. This means the ctime of all deployment files is changed every time any blasadmin command is run (even "show all"). If you have any job or script that monitors changes in those files, you would get an alert every time blasadmin is run.

       

      The proper way to do this is to use /bin/su to call the command as bladmin and to pass and export required environment variables right before. Like this:

       

      /bin/su - bladmin -c "(JAVA_HOME=$JAVA_HOME; CLASSPATH=$CLASSPATH; LD_LIBRARY_PATH=$LD_LIBRARY_PATH; PATH=$PATH; export JAVA_HOME CLASSPATH LD_LIBRARY_PATH PATH; $JAVA_HOME/bin/java -Xss1m -Djava.security.egd=file:/dev/../dev/urandom -Dblx.rootdir=$BLADELOGIC_HOME -Dblx.cmrootdir=$BLADELOGIC_HOME/br -classpath $CLASSPATH com.bladelogic.om.infra.app.util.BlAdmin $ARGS)"


      This will ensure that the java process is run as the bladmin user and any files created by it will automatically have the right ownership. The ctime of deployment files will not be touched unless an actual change is made to one of them,

       

      Here's the full version of my revised blasadmin script

      (commented and red lines are removed parts, green lines are new parts):

       

      Note: The paths may differ on your system, so adjust accordingly

       

      #!/bin/sh

      #

       

      BLADELOGIC_HOME=/opt/bladelogic/appserver/NSH

      JAVA_HOME=/opt/bladelogic/appserver/NSH/br/java

      BLDEPLOY=$BLADELOGIC_HOME/br

      STDLIB=$BLDEPLOY/stdlib

      CLASSPATH=$BLADELOGIC_HOME/br:$BLADELOGIC_HOME/br/deployments:$JAVA_HOME/jre/lib/rt.jar:$STDLIB:$BLADELOGIC_HOME/br/*.jar:$STDLIB/activation-1.1.jar:$STDLIB/activation.jar:$STDLIB/aix-feed-1.0-SNAPSHOT.jar:$STDLIB/animation-1.1.jar:$STDLIB/ant.jar:$STDLIB/arapi7603.jar:$STDLIB/aspectjlib.jar:$STDLIB/aspectjrt.jar:$STDLIB/aspectjtools.jar:$STDLIB/aspectjweaver.jar:$STDLIB/authapi-5.0.3.176.jar:$STDLIB/avctKVMIOLinux.jar:$STDLIB/avctKVMIOWin32.jar:$STDLIB/avctNuova.jar:$STDLIB/avctVMLinux.jar:$STDLIB/avctVMWin32.jar:$STDLIB/axiom-api-1.2.8.jar:$STDLIB/axiom-dom-1.2.8.jar:$STDLIB/axiom-impl-1.2.8.jar:$STDLIB/axis2-adb-1.5.jar:$STDLIB/axis2-adb-codegen-1.5.jar:$STDLIB/axis2-ant-plugin-1.5.jar:$STDLIB/axis2-clustering-1.5.jar:$STDLIB/axis2-codegen-1.5.jar:$STDLIB/axis2-corba-1.5.jar:$STDLIB/axis2-fastinfoset-1.5.jar:$STDLIB/axis2-java2wsdl-1.5.jar:$STDLIB/axis2-jaxbri-1.5.jar:$STDLIB/axis2-jaxws-1.5.jar:$STDLIB/axis2-jibx-1.5.jar:$STDLIB/axis2-json-1.5.jar:$STDLIB/axis2-kernel-1.5.jar:$STDLIB/axis2-metadata-1.5.jar:$STDLIB/axis2-mtompolicy-1.5.jar:$STDLIB/axis2-saaj-1.5.jar:$STDLIB/axis2-spring-1.5.jar:$STDLIB/axis2-transport-http-1.5.jar:$STDLIB/axis2-transport-local-1.5.jar:$STDLIB/axis2-xmlbeans-1.5.jar:$STDLIB/axis.jar:$STDLIB/bcel-5.1.jar:$STDLIB/bcmail-jdk15-136.jar:$STDLIB/bcprov-jdk15-136.jar:$STDLIB/binding-1.0.jar:$STDLIB/bladelogic_acm.jar:$STDLIB/bladelogic_blvmware.jar:$STDLIB/bladelogic_bsmintegration.jar:$STDLIB/bladelogic_caconvert.jar:$STDLIB/bladelogic_caformat.jar:$STDLIB/bladelogic_camodel.jar:$STDLIB/bladelogic_common.jar:$STDLIB/bladelogic_dbdiagnostics.jar:$STDLIB/bladelogic_deploy.jar:$STDLIB/bladelogic_gei.jar:$STDLIB/bladelogic_infra.jar:$STDLIB/bladelogic_infraui.jar:$STDLIB/bladelogic_licensing.jar:$STDLIB/bladelogic_patch.jar:$STDLIB/bladelogic_provisioning.jar:$STDLIB/bladelogic_spring_beans.jar:$STDLIB/bladelogic_ucs.jar:$STDLIB/bladelogic_virtualization.jar:$STDLIB/bladelogic_vsm.jar:$STDLIB/bladelogic_webservices-client.jar:$STDLIB/bladelogic_webservices.jar:$STDLIB/blas-1.4.0.jar:$STDLIB/blas-locale-1.4.0.jar:$STDLIB/bllocale.jar:$STDLIB/blmigration-tools.jar:$STDLIB/bmccui-2.0.jar:$STDLIB/castor-1.1.2.1-anttasks.jar:$STDLIB/castor-1.1.2.1-codegen.jar:$STDLIB/castor-1.1.2.1-ddlgen.jar:$STDLIB/castor-1.1.2.1.jar:$STDLIB/castor-1.1.2.1-jdo.jar:$STDLIB/castor-1.1.2.1-xml.jar:$STDLIB/catalina.jar:$STDLIB/catalina-optional.jar:$STDLIB/civiewer.jar:$STDLIB/cmdbapi7603.jar:$STDLIB/commons-codec-1.3.jar:$STDLIB/commons-collections-3.2.jar:$STDLIB/commons-configuration-1.3.jar:$STDLIB/commons-dbcp-1.4.jar:$STDLIB/commons-discovery-0.2.jar:$STDLIB/commons-el.jar:$STDLIB/commons-fileupload-1.2.jar:$STDLIB/commons-httpclient-3.0.1.jar:$STDLIB/commons-httpclient-3.1.jar:$STDLIB/commons-io-1.4.jar:$STDLIB/commons-lang-2.3.jar:$STDLIB/commons-lang-2.4.jar:$STDLIB/commons-logging-1.1.1.jar:$STDLIB/commons-logging-1.1.jar:$STDLIB/commons-modeler-2.0.1.jar:$STDLIB/commons-net-1.4.1.jar:$STDLIB/commons-net-2.2.jar:$STDLIB/commons-pool-1.5.4.jar:$STDLIB/concurrent.jar:$STDLIB/feed-common-1.0-SNAPSHOT.jar:$STDLIB/forms-1.0.5.jar:$STDLIB/geronimo-annotation_1.0_spec-1.1.jar:$STDLIB/geronimo-jaxws_2.1_spec-1.0.jar:$STDLIB/geronimo-saaj_1.3_spec-1.0.1.jar:$STDLIB/geronimo-stax-api_1.0_spec-1.0.1.jar:$STDLIB/geronimo-ws-metadata_2.0_spec-1.1.2.jar:$STDLIB/hfn-1.0-SNAPSHOT.jar:$STDLIB/httpcore-4.0.jar:$STDLIB/init-props.jar:$STDLIB/jakarta-oro-2.0.8.jar:$STDLIB/jalopy-1.5rc3.jar:$STDLIB/jasper-compiler.jar:$STDLIB/jasper-compiler-jdt.jar:$STDLIB/jasper-runtime.jar:$STDLIB/javatar-2.5.jar:$STDLIB/jaxb1-impl.jar:$STDLIB/jaxb-activation.jar:$STDLIB/jaxb-api-2.1.jar:$STDLIB/jaxb-api.jar:$STDLIB/jaxb-impl-2.1.7.jar:$STDLIB/jaxb-impl.jar:$STDLIB/jaxb-xjc-2.1.7.jar:$STDLIB/jaxb-xjc.jar:$STDLIB/jaxen-1.1.1.jar:$STDLIB/jaxp.jar:$STDLIB/jaxrpc.jar:$STDLIB/jboss-common.jar:$STDLIB/jboss-container.jar:$STDLIB/jboss-dependency.jar:$STDLIB/jboss-jmx.jar:$STDLIB/jboss-microcontainer.jar:$STDLIB/jboss-remoting.jar:$STDLIB/jboss-system.jar:$STDLIB/jboss-xml-binding.jar:$STDLIB/jcifs-1.2.9.jar:$STDLIB/jconsole-1.5.6.jar:$STDLIB/jconsole-adapter.jar:$STDLIB/jdbc-se2.0.jar:$STDLIB/jdom.jar:$STDLIB/jettison-1.0-RC2.jar:$STDLIB/jibx-bind-1.2.1.jar:$STDLIB/jibx-run-1.2.1.jar:$STDLIB/jlibdiff.jar:$STDLIB/jnpserver.jar:$STDLIB/jpa_types.jar:$STDLIB/jpcsc.jar:$STDLIB/jsafeFIPS.jar:$STDLIB/jsafeJCEFIPS.jar:$STDLIB/jsch-0.1.32.jar:$STDLIB/jsp-api.jar:$STDLIB/jsr173_1.0_api.jar:$STDLIB/jsr173_api-1.0.jar:$STDLIB/jta1.0.1.jar:$STDLIB/local_policy.jar:$STDLIB/log4j-1.2.14.jar:$STDLIB/log4j-1.2.15.jar:$STDLIB/looks-1.1.2.jar:$STDLIB/looks-1.2.2.jar:$STDLIB/lzvcnt.jar:$STDLIB/mail-1.4.jar:$STDLIB/mailapi.jar:$STDLIB/mex-1.5.jar:$STDLIB/mssqlserver.jar:$STDLIB/namespace.jar:$STDLIB/naming-factory.jar:$STDLIB/naming-resources.jar:$STDLIB/neethi-2.0.4.jar:$STDLIB/not-yet-commons-ssl-0.3.10.jar:$STDLIB/oaklandsw-http.jar:$STDLIB/objectprofiler.jar:$STDLIB/oel-feed-1.0-SNAPSHOT.jar:$STDLIB/oel-schema.jar:$STDLIB/opensaml-1.1.jar:$STDLIB/oracle.jar:$STDLIB/parser.jar:$STDLIB/pd5-1.0-SNAPSHOT.jar:$STDLIB/pdc-1.0-SNAPSHOT.jar:$STDLIB/rampart-core-1.4.jar:$STDLIB/rampart-policy-1.4.jar:$STDLIB/rampart-trust-1.4.jar:$STDLIB/redhat-feed-1.0-SNAPSHOT.jar:$STDLIB/redhat-schema.jar:$STDLIB/servlet-api.jar:$STDLIB/servlets-default.jar:$STDLIB/smack-3.0.4.jar:$STDLIB/smackx-3.0.4.jar:$STDLIB/smtp.jar:$STDLIB/SNMP4J-agent.jar:$STDLIB/SNMP4J.jar:$STDLIB/soapmonitor-1.5.jar:$STDLIB/solaris-feed-1.0-SNAPSHOT.jar:$STDLIB/solaris-schema.jar:$STDLIB/spin.jar:$STDLIB/spring.jar:$STDLIB/support-files-1.0-SNAPSHOT.jar:$STDLIB/suse-feed-1.0-SNAPSHOT.jar:$STDLIB/suse-schema.jar:$STDLIB/tibco-uddi-client3.0.jar:$STDLIB/tomcat-coyote.jar:$STDLIB/tomcat-http.jar:$STDLIB/tomcat-util.jar:$STDLIB/US_export_policy.jar:$STDLIB/windows-feed-1.0-SNAPSHOT.jar:$STDLIB/wiseman.jar:$STDLIB/woden-api-1.0M8.jar:$STDLIB/woden-impl-dom-1.0M8.jar:$STDLIB/ws-commons-util-1.0.1.jar:$STDLIB/wsdl4j-1.6.2.jar:$STDLIB/WSRegistryAPI7.6.jar:$STDLIB/wss4j-1.5.4.jar:$STDLIB/wstx-asl-3.2.4.jar:$STDLIB/xalan-2.7.0.jar:$STDLIB/xercesImpl-2.6.2.jar:$STDLIB/xercesImpl.jar:$STDLIB/xml-apis-1.3.02.jar:$STDLIB/xml-apis.jar:$STDLIB/xmlbeans-2.3.0.jar:$STDLIB/xml-resolver-1.2.jar:$STDLIB/xmlrpc-client-3.0.jar:$STDLIB/xmlrpc-common-3.0.jar:$STDLIB/xmlrpc-server-3.0.jar:$STDLIB/XmlSchema-1.4.3.jar:$STDLIB/xmlsec-1.4.1.jar:$STDLIB/xmlunit-1.2.jar:$STDLIB/xml-writer.jar:$STDLIB/xpp3_min-1.1.3.4.O.jar:$STDLIB/xstream-1.2.1.jar:$STDLIB/jboss.jar

      ARGS=$@

       

      pathadd() {

          if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then

              PATH="${PATH:+"$PATH:"}$1"

          fi

      }

       

      pathadd /opt/bladelogic/appserver/NSH/bin

      pathadd /opt/bladelogic/appserver/NSH/sbin

       

      #PATH=/opt/bladelogic/appserver/NSH/bin:/opt/bladelogic/appserver/NSH/sbin:$PATH

       

      LD_LIBRARY_PATH=${LD_LIBRARY_PATH:=}${LD_LIBRARY_PATH:+:}$BLADELOGIC_HOME/lib

       

      export JAVA_HOME CLASSPATH LD_LIBRARY_PATH PATH

       

      cd $BLDEPLOY

      #$JAVA_HOME/bin/java -Xss1m -Djava.security.egd=file:/dev/../dev/urandom -Dblx.rootdir=$BLADELOGIC_HOME -Dblx.cmrootdir=$BLADELOGIC_HOME/br -classpath $CLASSPATH com.bladelogic.om.infra.app.util.BlAdmin $ARGS

      #chown -R bladmin:bladmin $BLDEPLOY/deployments

      /bin/su - bladmin -c "(JAVA_HOME=$JAVA_HOME; CLASSPATH=$CLASSPATH; LD_LIBRARY_PATH=$LD_LIBRARY_PATH; PATH=$PATH; export JAVA_HOME CLASSPATH LD_LIBRARY_PATH PATH; $JAVA_HOME/bin/java -Xss1m -Djava.security.egd=file:/dev/../dev/urandom -Dblx.rootdir=$BLADELOGIC_HOME -Dblx.cmrootdir=$BLADELOGIC_HOME/br -classpath $CLASSPATH com.bladelogic.om.infra.app.util.BlAdmin $ARGS)"