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:

#### script to check every ten minutes if JIRA is up and restart it if it isn't
/bin/ps -ef |/bin/grep -q jira
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!!
/bin/cat $statusFile | mail -s "$statusStatus" $mailPerson
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



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 $?
[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 $?
[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. 


Renato Rudnicki



Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,323 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot