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

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

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

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
Colin Goudie Community Champion 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

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

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.

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

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.

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.

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
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

29,481 views 26 12
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