Script to Restart JIRA automatically

My JIRA server occasionally dies.  I've not been able to find any 'out of memory' errors, or anything else in the logs that would explain this.  So I give up and do the following little script:

#/bin/sh
#### script to check every ten minutes if JIRA is up and restart it if it isn't
mailPerson="jiraadmin@mydomain.com
statusFile="/tmp/status"
/bin/ps -ef |/bin/grep -q jira
lastStatus=$?
if [ $lastStatus != "0" ]; then
    /etc/init.d/jira start
    statusStatus="The JIRA service was down"
      /bin/cat << EOF > $statusFile
      I have just had to restart JIRA!!
EOF
/bin/cat $statusFile | mail -s "$statusStatus" $mailPerson
fi
exit 0

I set this in root's cron, and set it for every ten minutes.

In a nutshell: it doesn't work.

The same script is running for Confluence (with the ps suitably altered), and that doesn't work either.

Ideas ?

4 answers

Got it.  It was returning '0', because the grep was finding itself!

0 vote

Hi David, 

 

If you want to skip the returns of grep line, you can use this:

/bin/ps -ef |/bin/grep -q jira | grep -v grep

 

Regards, 

Renato Rudnicki

Hey Renato,

Yeah, that's what I did.  There was also an issue with the double quotes around the 0, but it seems to be working now.

 

Thanks.  smile

0 vote

Hi David, 

 

Your double quotes on 0 are correct. I believe you are expecting a wrong return from the $? variable. 

Have a look in my example:

[root@jira-clone ~]# ls /tmp
VMwareDnD  atlassian-confluence-5.8.4-x64.bin  hsperfdata_root  pluginversioncheckerthing  pulse-Pzck7gM0mRUD  ssl  ssl2  status  vmware-root  vmware-root-1857948889
[root@jira-clone ~]# 
[root@jira-clone ~]# echo $?
0
[root@jira-clone ~]# 
[root@jira-clone ~]# ls /directory-doesnt-exist
ls: cannot access /directory-doesnt-exist: No such file or directory
[root@jira-clone ~]# 
[root@jira-clone ~]# echo $?
2
[root@jira-clone ~]#

 

Exit status is a numerical value returned by every command upon its completion. As a rule, most commands return an exit status of 0 if they were successful, and 1 if they were unsuccessful.

Some commands return additional exit statuses for particular reasons. For example, some commands differentiate between kinds of errors and will return various exit values depending on the specific type of failure.

 

I've made some tests, and I believe what is causing this bad behaviour is your -q parameter. Try to run your script with no -q parameter on grep. 

Another thing you can do to start your scripts and run them in debug mode. You just need to add -x after /bin/sh: Like this:

/bin/sh -x

 

Hope this helps. 

Cheers, 

Renato Rudnicki

 

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

154 views 5 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you