Create a service for JIRA for Linux

logo-jiraAtlassian JIRA is a bug and issue tracker. Atlassian JIRA lets you priorities, assign, track, report and audit issues from software bugs, helpdesk tickets, project tasks to change requests. On a CentOS 6.5 Linux install, an instance of JIRA was installed. Upon completion, a service to automate the start, stop, restart, and status needed to be created manually.

One of the considerations for this script is that it needed to be executed by the user account associated with this application, which happens to be the user jira. So instead of adding to each executable line su - jira, I decided to wrap the entire script. While I don't know if this is a good and safe practice, I can state that it works. The script will execute as the desired user service account, jira.

Make whatever modifications needed to your environment from the user name to the location of the jira installation. This script is actually ported over and slightly modified from another Atlassian product that automatically generated this script with it's installation.

#!/bin/bash
# chkconfig: 2345 12 88

su - jira <<EOF

# Jira Linux service controller script
cd "/opt/jira/bin"

case "$1" in
 start)
 ./start-jira.sh
 ;;
 stop)
 ./stop-jira.sh
 ;;
 restart)
 ./stop-jira.sh
 ./start-jira.sh
 ;;
 *)
 echo "Usage: $0 {start|stop|restart}"
 exit 1
 ;;
esac
EOF

However, I wanted more. This modified script adds some echos, a status, ripped and heavily modified from earlier scripts, and reduces the chatter. While this did work in a development installation, it may or may not work for everyone. The first thing that comes to mind, is if there are multiple services with the text "[ c ]atalina.base" in it, this would then return a false result. Other than that, make any modifications needed for your environment. This script should also work on other Atlassian products, including Confluence. This hasn't been tested on other applications.

For some reason, WordPress is not permitting the [ c ] to display without the spaces, for the script to work, be certain to remove the spacing withing those brackets.

#!/bin/bash
# chkconfig: 2345 12 88

su - jira <<EOF

# jira Linux service controller script
cd "/opt/jira/bin"

case "$1" in
 start)
 echo "Starting $(basename $0)"
 ./start-jira.sh &> /dev/null
 ;;
 stop)
 echo "Stopping $(basename $0)"
 ./stop-jira.sh &> /dev/null
 ;;
 restart)
 echo "Restarting $(basename $0)"
 ./stop-jira.sh &> /dev/null
 ./start-jira.sh &>; /dev/null
 ;;
 status)
 if [ $( ps aux | grep "[ c ]atalina.base=$CATALINA_HOME" | wc -l ) = 0 ]; then
 echo "$(basename $0) is not running."
 else
 echo "$(basename $0) pid $( ps a | grep "[ c ]atalina.base=$CATALINA_HOME" | cut -f2 -d" " ) is running..."
 fi
 ;;
 *)
 echo "Usage: $0 {start|stop|restart|status}"
 echo $(basename $0)
 exit 1
 ;;
esac
EOF

Once, the script is created, put it into the /etc/init.d directory, make it executable, and autorun.

chmod +x /etc/init.d/jira
chkconfig jira on

To start the service manually.

service jira start

To stop the service manually.

service jira stop

To restart the service manually.

service jira restart

To see JIRA in action, http://xxx.xxx.xxx.xxx:8080