3 Replies Latest reply on Aug 17, 2012 3:49 AM by Stephan Pelikan

    How to control managed server by shell script?

    MJ Kim Newbie

      Hi All,

       

       

      I have the plan to construct my system with JBoss AS7 as a application server.

      And I want to configure domain at each server. Some managed servers belong to each domain.

       

      I want to control each of my managed servers by shell script.

       

      For example,

       

      my_domain

      - managed1

      - managed2

       

      and there are serveral shell script files,

       

      start_managed1.sh

      stop_managed1.sh

      ....

       

      I've read many articles and books, but I coudn't find any.

       

      How can i do this?

        • 1. Re: How to control managed server by shell script?
          James Perkins Master

          If I'm understanding correctly you want to run CLI scripts from bash. You can run any CLI command from the command line or a bash script.

           

          The following script would lost all loggers that are defined in the default profile.

          $JBOSS_HOME/bin/jboss-cli.sh --connect "/profile=default/subsystem=logging/logger=*:read-resource"
          
          • 2. Re: How to control managed server by shell script?
            Stephan Pelikan Newbie

            Hello,

             

            For starting/stopping only servers/server-groups (not the entire domain) through cli you can use:

             

            /server-group=main-server-group:stop-servers

            /host=local/server-config=server-one:stop

             

            Regards,

            Stephan

            • 3. Re: How to control managed server by shell script?
              Stephan Pelikan Newbie

              This is my start-script:

              #!/bin/sh
              
              CUSTOMER="appA"
              SERVER="01"
              
              if [ `whoami` != "wwwsrv" ];
              then
                echo "Switching to User wwwsrv"
                su - wwwsrv -c "/appl/${CUSTOMER}/bin/startjboss.sh"
                exit
              fi
              
              PDC=`wget -q -O - "domaincontroller.provider.at:9999"`
              if [ "e${PDC}" = "e" ]; then
                 echo "Domain-Controller-Master on server01 not running - please start using server01:/appl/domaincontroller/bin/startdomain.sh"
                 exit
              else
                 echo "Domain-Controller-Master is running - this is good"
              fi
              
              # this test is not necessary on server01 because on server01 only the master-domaincontroller is needed
              if [ ! "${SERVER}" = "01" ]; then
                  DCPID=`ps -ef |grep wwwsrv|grep "\-D\[Host Controller\] "|awk '{print $2;}'`
                  if [ "e${DCPID}" = "e" ]; then
                      echo "Domain-Controller-Slave on server02 not running - please start using /appl/domaincontroller/bin/startdomain_slave.sh"
                      exit
                  else
                      echo "Domain-Controller-Slave is running - this is good"
                  fi
              fi
              
              PID=`ps -ef |grep ${CUSTOMER}${SERVER}|grep -v grep|awk '{print $2;}'`
              if [ !  "e${PID}" = "e" ]; then
                 echo "${CUSTOMER}${SERVER} is already running"
                 exit
              fi
              
              echo "Will start up ${CUSTOMER}${SERVER}"
              export JAVA_HOME=/opt/jdk1.7
              /appl/domaincontroller/jboss-as-7.1.2.Final/bin/jboss-cli.sh \
                --controller=domaincontroller.provider.at:9999  \
                --user=admin --password=xxxxxx \
                --commands="connect,/host=master/server-config=${CUSTOMER}${SERVER}:start"
              

              The script asumes that on server01 the domain-controller-master is hostet and all jboss-servers are named like "appA01", "appB01", etc. On other servers like server02 a domain-controller-slave is hostet and all jboss-servers named like "appA02", "appB02", etc. So there are clusters of jboss-servers for each application A, B.

               

              The stop-script:

               

              #!/bin/sh
              
              CUSTOMER="appA"
              SERVER="01"
              
              if [ `whoami` != "wwwsrv" ];
              then
                echo "Switching to User wwwsrv"
                su - wwwsrv -c "/appl/${CUSTOMER}/bin/stopjboss.sh"
                exit
              fi
              
              PDC=`wget -q -O - "domaincontroller.provider.at:9999"`
              if [ "e${PDC}" = "e" ]; then
                 echo "Domain-Controller-Master on server01 not running - please start using server01:/appl/domaincontroller/bin/startdomain.sh"
                 exit
              else
                 echo "Domain-Controller-Master is running - this is good"
              fi
              
              # this test is not necessary on server01 because on server01 only the master-domaincontroller is needed
              if [ ! "${SERVER}" = "01" ]; then
                  DCPID=`ps -ef |grep wwwsrv|grep "\-D\[Host Controller\] "|awk '{print $2;}'`
                  if [ "e${DCPID}" = "e" ]; then
                     echo "Domain-Controller-Slave on server02 not running - please start using /appl/domaincontroller/bin/startdomain_slave.sh"
                     exit
                  else
                     echo "Domain-Controller-Slave is running - this is good"
                  fi
              fi
              
              PID=`ps -ef |grep ${CUSTOMER}${SERVER}|grep -v grep|awk '{print $2;}'`
              if [ "e${PID}" = "e" ]; then
                 echo "${CUSTOMER}${SERVER} is not running"
                 exit
              fi
              
              echo "Will shut down ${CUSTOMER}${SERVER}"
              export JAVA_HOME=/opt/jdk1.7
              /appl/domaincontroller/jboss-as-7.1.2.Final/bin/jboss-cli.sh \
                --controller=domaincontroller.provider.at:9999  \
                --user=admin --password=xxxxxx \
                --commands="connect,/host=master/server-config=${CUSTOMER}${SERVER}:stop"
              
              echo -n "Waiting for shutdown"
              for i in {1,2,3,4,5,6,7,8,9,10}; do
                 echo -n "."
                 RUNNING=`ps -ef|grep ${PID}|grep -v grep`
                 if [ "e${RUNNING}" = "e" ]; then
                    echo "done"
                    exit
                 fi
                 sleep 1
              done
              
              echo "Killing JBoss (PID:${PID})"
              kill -9 ${PID}
              

               

              I hope this helpes any of you.