juanesech
3/2/2017 - 1:56 PM

jboss_AutoDeploy.sh

#!/bin/bash
logFile=Deploy_`date "+%Y-%m-%d-%H%M"`.log
{
  ##########################################################
  #Variables
  hostctl=172.23.5.20
  cliPath=/opt/EAP-6.3.0/jboss-eap-6.3/bin/jboss-cli.sh
  error=JBAS010839

  app1=160014.war
  app2=160018.ear
  app3=WebScau2.war
  app4=clusterjsp.war
  app5=diplomas-integracion.war
  app6=diplomas.war
  app7=jboss-helloworld.war
  app8=jboss-temperature-converter.war
  app9=jtds-1.2.5.jar
  app10=maestro.ear
  app11=notificaciones.war
  app12=protocolo.ear
  app13=reca.ear
  app14=sac.ear
  app15=scau.ear
  app16=sqljdbc4.jar
  app17=wsAfiliados.ear

  ###########################################################
  #Functions

  update()
  {

    y=`readlink -f $a`
    echo 'deploy -f' $y > command.cli
    log=`$cliPath --connect controller=$hostctl file=command.cli`
    >command.cli
    if [ "$log" == *$error* ]; then
      echo "Ha ocurrido un error con el despliege"
    else
      echo "Despliegue exitoso del paquete: " $a
    fi
    echo $log
    echo
  }


  deploy()
  {

#    x=`readlink -f $a`
#    echo 'deploy' $x '--all-server-groups' > command.cli
    # logd=`$cliPath --connect controller=$hostctl file=command.cli`
    # >command.cli
    # if [[ $logd == *$error* ]]; then
    #   echo "Ha ocurrido un error con el despliege del paquete: " $a
    # else
    #   echo "Despliegue exitoso del paquete: " $a
    # fi
    # echo $logd
    # echo

    echo "El despliegue no se puede llevar a cabo porque el paquete nunca ha sido desplegado antes"
  }
  ###########################################################

  for a in `ls | egrep '\.ear$|\.war$'`; do
    for z in `$cliPath --connect controller=$hostctl deploy`; do
      if [ $z = $a ]; then
        echo
        aux=$z
      fi
    done
      if [ "$aux" = "$a" ]; then
        echo
        echo Updating $a
        update
      else
        echo
        echo Deploying $a
        deploy
      fi
  done
  echo `date "+%Y-%m-%d-%H:%M"`
  echo "Finished"
  t=`date "+%Y-%m-%d-%H%M"`
  mv $a ./repo/${a}${t}
} > $logFile
###########################################################
#Directory
case $a in
  $app1 )
  email=
    ;;
  $app2 )
  email=
    ;;
  $app3 )
  email=
    ;;
  $app4 )
  email="jechavarria@3htp.com aferrer@3htp.com"
    ;;
  $app5 )
  email=
    ;;
  $app6 )
  email=
    ;;
  $app7 )
  email=
    ;;
  $app8 )
  email=
    ;;
  $app9 )
  email=
    ;;
  $app10 )
  email=
    ;;
  $app11 )
  email=
    ;;
  $app12 )
  email=
    ;;
  $app13 )
  email=
    ;;
  $app14 )
  email=
    ;;
  $app15 )
  email=
    ;;
  $app16 )
  email=
    ;;
  $app17 )
  email=
    ;;
esac

###########################################################
mv $logFile ./repo/
mail -s "Despliegue automatico jboss Desarrollo" $email < repo/$logFile
###################
# By: jechavarria #
###################