1

I have to write a script to run JBoss and also verify and inform JBoss has just started in system startup. Below code is to related to verifying part. Please correct logical and syntax mistakes I have done.

Log record I am greping:

2017-10-27 12:04:13,933 INFO [org.jboss.bootstrap.microcontainer.ServerImpl] (main) JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221053)] Started in 1m:1s:804ms

!/bin/bash

maxLoops=30 numLines=200 timeToSleep=3 success=0 Server_Log=$(/path_for_log/server.log)

        for (( try=0; try < maxLoops; ++try ));
        do
           atail=`tail -n $numLines $Server_Log | grep "Started" | awk {'print $12'}`

        if [[ $atail == "Started" ]]
                then
                        success=1
                        break
              fi
                sleep $timeToSleep
        done
        if (( success ));
        then
                echo "Jboss started successfully"
        else
                echo "successful starting of Jboss is not ensured"

fi

Please find the error below that I am getting while executing the script as root:

$ ./verify_jboss.sh:
 line 3: /log_path/server.log: Permission denied
slm
  • 363,520
  • 117
  • 767
  • 871
Prabash
  • 65
  • 3
  • 11

2 Answers2

1

If possible check if Jboss is listening on the port:

if curl -Is http://localhost:80/ > /dev/null
then
   echo OK
else
   echo FAIL
fi

You just need one external program: curl

Edit:

Another approach is to test for a specific content, say Contact on the web page. Only if the webserver is running and there is a connection to the database, it will respond correctly.

if grep -qc "Contact" <(curl -s http://localhost/)
then
    echo OK
else
    echo FAIL
fi

The construction <(curl ...) (Process Substitution) will be seen by grep as a file. curl has option -s for silent to avoid transfer progress. grep has option -qc to suppress output and count the occurrence of the matched text. If one or more count of Contact the result is OK (exit code 0).

hschou
  • 2,845
  • 12
  • 15
  • Thank for your reply ,but I think it doesn't work . because even jboss stopped, Still port 80 is Listen by httpd service , Because We are starting jboss by manual script with nohup – Prabash Oct 27 '17 at 11:02
0

You could try making request and then checking for some specific content:

curl_result=$(curl -Is https://www.yoururl.com)

if  echo "$curl_result" | grep  "some_text_generated_by_JBOSS"; then
  echo "Server ok" 
fi
ivane
  • 1