What is the best way to autostart STASH on linux debian/ubuntu platform

Giovanni Cândido da Silva May 5, 2012

I Want a script to statup stash on linux ubuntu/debian.

This is a self question. I know a possible answer, but I can't comment on the Stash Documentation (I think is disabled). I made this question to share my script and get feedback from others.

5 answers

1 accepted

11 votes
Answer accepted
Giovanni Cândido da Silva May 5, 2012

Create a startup script on /etc/init.d/stash with the contents:

#!/bin/bash

# RUN_AS: The user to run fisheye as. Its recommended that you create a separate user account for security reasons
RUN_AS=stash

# STASH_INSTALLATION: The path to the Stash installation. Its recommended to create a symbolic link to the latest version so 
# the process will still work after upgrades. 
STASH_INSTALLATION="/opt/atlassian/stash"
STASH_HOME="/var/atlassian/application-data/stash"
stashctl() {
        if [ "x$USER" != "x$RUN_AS" ]; then
                su - "$RUN_AS" -c "export STASH_HOME=$STASH_HOME;$STASH_INSTALLATION/bin/$1"
        else
                "export STASH_HOME=$STASH_HOME;$STASH_INSTALLATION/bin/$1"
        fi
}

case "$1" in
        start)
                stashctl start-stash.sh
                ;;
        stop)
                stashctl stop-stash.sh
                ;;
        restart)
                stashctl stop-stash.sh
                sleep 10
                stashctl start-stash.sh
                ;;
        *)
                echo "Usage: $0 {start|stop|restart}"
esac

exit 0

This script is based on a Fisheye startup script. I recommend create a stash user, set the permissions to that user, and create a symlink to easy upgrades:

adduser stash
cd /opt/atlassian
ln -s atlassian-stash-1.0.0 stash
chown stash.stash -R /opt/atlassian/stash
chown stash.stash /var/atlassian/application-data/stash/

To startup on the system boot:

update-rc.d stash defaults

Denny Schäfer November 7, 2012

In my opinion its better to give the stash user only on the logs, temp, work folder the rights.

cd /opt/atlassian/stash
sudo chown -R stash:root logs temp work

1 vote
Melanie Wright
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 27, 2012

FYI, I've submitted a documentation request here: https://jira.atlassian.com/browse/STASH-2731

paulwatson
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 1, 2013
1 vote
Colin Goudie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2012

Other alternative is to use something like daemontools. The benefit of this over the init script above is it will monitor the process and ensure it restarts if errors occur. Plus you can set it up to have much nicer environment variable handling etc..

It is more involved initially creating correct run scripts etc.. but I find superior to the init scripts

Giovanni Cândido da Silva May 17, 2012

I agree with you Colin Goudie.

I you try to do this with init scripts. If you have some script ready and want share, I will be grateful

Pierre Lhoste July 30, 2012

Yes, by all means, I'd love to see a daemontools tutorial for stash !

In the meantime, thanks Giovanni for this very usefull startup script.

0 votes
Alexey_Efimov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2013

I just released my deb-package to outside. It maybe usefull for installing Stash on Ubuntu:

https://bitbucket.org/lelik/atlassian-stash-deb

Feel free to test and post issues to tracker.

0 votes
Pierre Lhoste September 27, 2012

Thx Melanie :)

And juste because I stumbled on that myself, when installing any atlassian product as a service on Debian flavored linuxes (Debian, Ubuntu), one can use the above script (I use it for Jira and Stash). It's not fully LSB compliant, but it works well.

One has to remember if said product uses a SSL connector (via catalina) to also copy the .keystore (after importing SSL certificate) to the "dedicated user account's homedir" (created for this script's usage) too.

Not stash specific, but as you opened a 'linux services' issue, might as well point that out.

Have a nice day

EDIT1 : cf this Running+JIRA+over+SSL+or+HTTPS

EDIT2 : following previous link, for the 'service user'

1 ) either generate the SSL cert and import it (.keystore) while logged under the service user's account, then in 'server.xml' specify its location with

<Connector port="443" maxHttpHeaderSize="8192"
           (...)
           SSLEnabled="true"
           (...)
           keystorePass="password"             
           keystoreFile="/home/serviceuser/.keystore" />

Points "SSLEnabled", "KeystorePass", and "keystoreFile" are not documented in the referenced article's body, but are all compulsory. Omitting 'keystoreFile' won't result in any error in the 'catalina.log' file, the '.keystore' is found, but... it won't be loaded properly by tomcat.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events