There is an init.d script posted at https://confluence.atlassian.com/display/STASH/Running+Stash+as+a+Linux+service#RunningStashasaLinuxservice-Usinganinit.dscript , but it is geared more toward Debian-based systems than RHEL-based systems. As is, the script has issues with chkconfig. Is there an init.d script available for us who use the RHEL-based systems?
This is a self-answer question. I'm posting a script below.
Personal solution:
#!/bin/sh
#
# stash     Startup script for stash.
#
# chkconfig: 2345 85 28
# description: Initscript for Atlassian Stash
### BEGIN INIT INFO
# Provides: $stash
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Initscript for Atlassian Stash
# Description: Automatically start Atlassian Stash when the system starts up.
#              Provide commands for manually starting and stopping Stash.
### END INIT INFO
#
# Author: Billy Wilson
#         <billybob.wilson AT gmail.com>.
# Source function library
. /etc/rc.d/init.d/functions
# RUNUSER: The user to run stash as
RUNUSER=stash
# STASH_INSTALLDIR: The path to the Stash installation directory
STASH_INSTALLDIR="/usr/local/src/atlassian-stash-latest"
# STASH_BINDIR: The path to the Stash installation binaries
STASH_BINDIR="$STASH_INSTALLDIR/bin"
# STASH_HOME: The path to the Stash home directory
STASH_HOME="/var/lib/stash"
# STASH_PID: The path to the Stash PID file
STASH_PID="$STASH_INSTALLDIR/work/catalina.pid"
# For SELinux we need to use 'runuser' instead of 'su'
if [ -x /sbin/runuser ]
then
    SU=runuser
else
    SU=su
fi
# Set defaults for Stash name and description
NAME=stash
DESC="Atlassian Stash"
# Read configuration variable file if present
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
# Function to run commands as $RUNUSER with $STASH_HOME exported
run_with_home() {
    if [ "$RUNUSER" != "$USER" ]
    then
        $SU - "$RUNUSER" -c "export STASH_HOME=$STASH_HOME; $STASH_BINDIR/$1"
    else
        export STASH_HOME=$STASH_HOME; $STASH_BINDIR/$1
    fi
}
script_result=0
start(){
    [ -x "$STASH_BINDIR/start-stash.sh" ] || exit 5
    STASH_START=$"Starting $NAME service: "
    if [ -e $STASH_PID ]
    then
        echo $"$NAME is already running as PID `cat $STASH_PID` (or the PID file is dead)."
        echo_failure
        echo
        exit 1
    else
        echo -n "$STASH_START"
        run_with_home start-stash.sh > /dev/null
        sleep 2
        pid=`head -n 1 "$STASH_PID" 2>/dev/null`
        if [ "x$pid" != x ]
        then
            success "$STASH_START"
            echo
        else
            failure "$STASH_START"
            echo
            script_result=1
        fi
    fi
}
stop(){
    [ -x "$STASH_BINDIR/stop-stash.sh" ] || exit 5
    echo -n $"Stopping $NAME service: "
    if [ -e "$STASH_HOME/.lock" ]; then
        run_with_home stop-stash.sh > /dev/null
        ret=$?
        if [ $ret -eq 0 ]
        then
            echo_success
        else
            echo_failure
            script_result=1
        fi
    else
        # not running; per LSB standards this is "ok"
        echo_success
    fi
    echo
}
restart(){
    stop
    start
}
condrestart(){
    [ -e "$STASH_HOME/.lock" ] && restart || :
}
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status -p "$STASH_PID" stash
    script_result=$?
    ;;
  restart)
    restart
    ;;
  condrestart|try-restart)
    condrestart
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}" >&2
    exit 2
esac
exit $script_result
I realise this is an old thread, but I wanted to say thanks. Also I would offer that a "standard" RHEL/CentOS init script usually sources /etc/sysconfig/stash as opposed to /etc/default/stash if it exists to allow for "configuration" such as directories, users, etc. without customizing the script itself.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks again! I was glad to find this and it works great (I made the same change).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
i have some trouble with the init script. The Start is working perfectly but shutdown dont get run on system reboot.
RedHat checks for a lock file for your script in /var/lock/subsys/<scriptname> or it won't run your K* scripts.
You need to add an touch in the start routine and a rm -f in the stop routine.
Regards,
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Billy,
There is a script for FishEye that I think that can help you:
Could you please try it just editing the paths to Stash installation and tell me how it goes for you?
Regards,
Celso Yoshioka
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your response. I edited the paths and ran it, but the functionality of that script doesn't align well with what I would expect from an init.d script in RHEL. For example, `service stash status` tails a log file, but I would expect it to report if the service is running, along with a PID if available.
Also, it doesn't use the sourced functions in /etc/rc.d/init.d/functions, such as `success`, `failure`, `echo_success`, `echo_failure`, and `status`. Using these functions standardizes the format of `service stash` output with with the rest of my services.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
 
 
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.