Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
we have a JBOSS restart script scheduled in cron. When we execute manually script is working fine. But even in cron, script is getting executed, but JBoss is not getting started properly. I tried by updated Environment variables in /etc/crontab and also updated PATH variable in scripts. But I m unable to trace the issue
Below is the script.
Script1 calls script2
Script1
=======
1 #!/bin/bash
2 export PATH=/usr/java/jdk1.6.0_26/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin
3
4 application_restart()
5 {
6
7 echo "$runDate";
8
9 if [ $app_url = "https://IP:7443/event-server/xmlrpc" ] ; then
10 echo "URL_CONNECTION_EXCEPTION Occured; so restaring the application. $runDate"
11 MAIL_CONTENT="OpenNms Event Processor URL is available but HQEventServer is not available, hence redeploying HQEventServer application - Date:$(date)"
12 echo "MAIL TO:$MAIL_TO"
13 echo "MAIL_SUBJECT:$MAIL_SUBJECT"
14 echo "MAIL_CONTENT:$MAIL_CONTENT"
15 echo $MAIL_CONTENT | /usr/bin/mutt -F /root/.amuttrc -e 'set content_type="text/html"' "$MAIL_TO" -s "$MAIL_SUBJECT"
16 touch $JBOSS_APP_LOCATION/event-server-avis.war
17 echo "Sleeping for 60 secs to check app availability"
18 sleep 60
19 $JAVA_HOME/bin/java -cp $SCRIPT_HOME JbossPingerUpgraded "https://IP:7443/event-server/xmlrpc" "60000"
20 status=$?
21
22 if [ $status -eq 0 ] ; then
23 MAIL_CONTENT="HQEventServer URL is available post redeployment - Date:$(date)"
24 MAIL_SUBJECT="****** : HQEventServer URL is available post redeployment"
25 echo "Event Server is running"
26 else
27 MAIL_CONTENT="HQEventServer URL is not available post redeployment, please check immediately - Date:$(date)"
28 MAIL_SUBJECT="****** : HQEventServer URL is not available post redeployment"
29 echo "Event Server is not running"
30 fi
31
32 echo $MAIL_CONTENT | /usr/bin/mutt -F /root/.amuttrc -e 'set content_type="text/html"' "$MAIL_TO" -s "$MAIL_SUBJECT"
33
34 exit 0
35 else
36 echo "URL_CONNECTION_EXCEPTION Occured; so restarting the jboss server. $runDate"
37 $JBOSS_SERVER_HOME/bin/jboss_stop_start.sh >> /var/log/jboss/jboss_stop_start.log
38 exit 0
39 fi
40
41 }
42
43 JAVA_HOME=/usr/java/jdk1.6.0_26
44 JBOSS_SERVER_HOME=/mnt/raid5/jboss-4.2.2.GA
45 JBOSS_APP_LOCATION=$JBOSS_SERVER_HOME/server/all/farm
46 SCRIPT_HOME=/home/rapadmin/Dev_Backup/rapadmin-scripts/jboss_pinger
47
48 MAIL_TO="***@****"
49 MAIL_SUBJECT="****** JBOSS : HQ Event Server application restart"
50
51 ### ERRORS ARE DEFINED HERE ###
52 jboss_pinger_connection_exception=1
53 jboss_pinger_general_exception=2
54 jboss_pinger_input_error=3
55
56 ### URL to Check is Assigned HERE ###
57 url_to_check="https://IP:7443/opennms-event-processor/xmlrpc https://IP:7443/event-server/xmlrpc"
58 url_timeout="60000"
59
60 ### LOGIC IMPLEMENTATION BELOW ####
61 jboss_stop_start_Pid=new
62 jboss_stop_start_Pid=`ps -aef |grep -i "jboss_stop_start.sh" | grep -v grep|tr -s " " ":"|cut -d ":" -f2`
63 runDate=`date`
64
65 echo "***********************************************"
66
67 if [ ${jboss_stop_start_Pid}new != new ]
68 then
69 echo "JBoss stop_start script is already running on this machine; so no need to call jboss_stop_start from here. $runDate"
70 exit 0
71 fi
72
73 sleep 3
74
75 failure_count=0
76
77 for app_url in $url_to_check
78 do
79 $JAVA_HOME/bin/java -cp $SCRIPT_HOME JbossPingerUpgraded "$app_url" "$url_timeout"
80 result=$?
81 echo "Result is $result"
82
83 case "$result" in
84 0)
85 echo "No ERROR $runDate";
86 ;;
87 1)
88 failure_count=`expr $failure_count + 1`
89 application_restart
90 ;;
91 2)
92 failure_count=`expr $failure_count + 1`
93 application_restart
94 ;;
95 3)
96 echo "$runDate";
97 echo "JBOSS_PINGER_PROGRAM_INPUT_ERROR occured; Need to pass the complete URL as a argument. $runDate"
98 exit 1
99 ;;
100 esac
101
102 done
103
104 exit 0
Script2
========
1 #!/bin/bash
2 export PATH=/usr/java/jdk1.6.0_26/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/bin:/opt/dell/srvadmin/sbin:/root/bin
3 export JBOSS_HOME=/mnt/raid5/jboss-4.2.2.GA
4 export APPSERVER_HOME=$JBOSS_HOME/server/all/conf/
5 export JAVA_HOME=/usr/java/jdk1.6.0_26
6
7
8 LOG_FILE_LOCATION=/var/log/jboss
9 MAILTO="***@***"
10 JBOSSIP="IP"
11
12 if [ -d $LOG_FILE_LOCATION ]
13 then
14 echo "$LOG_FILE_LOCATION Directory already exists"
15 else
16 echo "$LOG_FILE_LOCATION doesn't exists, Creating now"
17 mkdir -p $LOG_FILE_LOCATION
18 fi
19
20 jboss_Pid=`ps -aef | grep -i "jboss.Main" | grep -i "program.name=run.sh" | grep -v grep | tr -s " " ":" | cut -d":" -f2`
21
22 if [ ${jboss_Pid}new = new ] ; then
23 echo "Jboss is not running"
24 else
25 echo "Jboss is running with PID::$jboss_Pid"
26 echo -en "Stopping JBOSS process started at $(date)"
27 $JBOSS_HOME/bin/shutdown.sh -S
28 echo "Sleeping for 20 secs"
29 sleep 20
30 fi
31
32 jboss_Pid=new
33 jboss_Pid=`ps -aef | grep -i "jboss.Main" | grep -i "program.name=run.sh" | grep -v grep | tr -s " " ":" | cut -d":" -f2`
34
35 echo "The jbossPid is $jboss_Pid"
36
37 if [ ${jboss_Pid}new != new ]
38 then
39 echo "Jboss is not shutdown yet using Kill option"
40 kill -9 $jboss_Pid
41 fi
42
43 echo "Deleting tmp and work directory of JBoss"
44 rm -rf $JBOSS_HOME/server/all/tmp
45 rm -rf $JBOSS_HOME/server/all/work
46
47 #while loop
48 STOP_FLAG=0
49 COUNTER=0
50 while [ $COUNTER -lt 5 ]; do
51 if [ $(/usr/bin/nc -zv 127.0.0.1 8080 2>&1 | grep -ic succeeded) -eq 0 ]; then
52 echo -e "Jboss process is not available"
53 STOP_FLAG=1
54 break;
55 fi
56 let COUNTER=$COUNTER+1
57 sleep 10
58 done
59
60 COUNTER=0
61 START_FLAG=0
62 SCRIPT_RETURN_STATUS_FLAG=0
63
64 if [ $STOP_FLAG -eq 1 ]; then
65
66 $JBOSS_HOME/bin/run.sh -b 0.0.0.0 -c all >> $LOG_FILE_LOCATION/jboss_startup_$(date -I).log 2>&1 &
67 echo -en "Starting JBOSS service..."
68
69 while [ $COUNTER -lt 5 ]; do
70 if [ $(/usr/bin/nc -zv 127.0.0.1 8080 2>&1 | grep -ic succeeded) -eq 1 ]; then
71 echo -e "Port 8080 is listening"
72 START_FLAG=1
73 break;
74 fi
75 let COUNTER=$COUNTER+1
76 sleep 10
77 done
78
79 if [ $START_FLAG -eq 1 ]; then
80 echo -e "Jboss startup has initiated, application deployment is going on"
81 MAIL_SUBJECT="****** JBOSS($JBOSSIP) Start Stop Script Successfull - $(date '+%d.%m.%Y %H:%M')"
82 MAIL_BODY="<strong>****** JBOSS($JBOSSIP) Service was Stopped and Started Successfully</strong>"
83 echo "JBOSS started sucessfully"
84 else
85 echo -e "Jboss startup has Failed"
86 MAIL_SUBJECT="****** JBOSS($JBOSSIP) Start Stop Script Failed - $(date '+%d.%m.%Y %H:%M')"
87 MAIL_BODY="<strong>****** JBOSS($JBOSSIP) Service Starting Failed</strong>"
88 fi
89
90 else
91 MAIL_SUBJECT="****** JBOSS($JBOSSIP) Start Stop Script Failed - $(date '+%d.%m.%Y %H:%M')"
92 MAIL_BODY="<h3>****** JBOSS($JBOSSIP) Service Failed to STOP. Now running in a Unstable state</h3>"
93 echo -e "Failed"
94 echo -e "****** JBOSS($JBOSSIP) Service Failed to STOP. Now running in a Unstable state"
95
96 fi
97
98 echo $MAIL_BODY | /usr/local/bin/mutt -e 'set content_type="text/html"' "$MAILTO" -s "$MAIL_SUBJECT"
99
100
101 exit;
please use [code]here comes your script[/code] tags to keep formatting
you can try to save stdout and stderr of your scripts and set -xv to see what's happened
I do not get any error. I receive message that Script is started successfully, but the applications inside is not getting deployed fully when executed over cron alone.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.