Installation from binary

Install Stash and Git, create git user

Note

This guide uses git.example.com and x.y.z for illustrative purpose. Replace with your domain and the used Stash version as appropriate.

First, download the Stash binary for your CPU architecture and verify the GPG signature, as described on the Stash download page.

Next, copy the downloaded Stash binary to /usr/local/bin/ (renaming it to “stash”) and make it executable:

sudo cp stash-x.y.z-linux-amd64 /usr/local/bin/stash
sudo chmod 755 /usr/local/bin/stash

Make sure git and git-lfs are installed on your system. On Debian GNU/Linux you can use:

sudo apt install git git-lfs

Create a user git on the system. Stash will run as that user, and when accessing git through SSH (which is the default), this user is part of the URL (for example in git clone git@git.example.com:YourOrg/YourRepo.git the git before the @ is the user you’ll create now). On Debian, Ubuntu and their derivatives that’s done with:

sudo adduser --system --shell /bin/bash --gecos 'Git Version Control' \
  --group --disabled-password --home /home/git git

On Linux distributions not based on Debian/Ubuntu (this should at least work with Red Hat derivatives like Fedora, CentOS etc.), run this instead:

sudo groupadd --system git
sudo useradd --system --shell /bin/bash --comment 'Git Version Control' \
   --gid git --home-dir /home/git --create-home git

Create directories Stash will use

Now create the directories Stash will use and set access permissions appropriately:

sudo mkdir /var/lib/stash
sudo chown git:git /var/lib/stash && sudo chmod 750 /var/lib/stash

This is the directory Stash will store its data in, including your Git repositories.

sudo mkdir /etc/stash
sudo chown root:git /etc/stash && sudo chmod 770 /etc/stash

This is the directory Stash’s config, called app.ini, is stored in. Initially it needs to be writable by Stash, but after the installation you can make it read-only for Stash because then it shouldn’t modify it anymore.

Optional: Set up database

When using sqlite as Stash’s database, nothing needs to be done here.

If you need a more powerful database, you can use MySQL/MariaDB or PostgreSQL (apparently sqlite is good enough for at least 10 users, but might even suffice for more).

See Stash’s Database Preparation guide for setup instructions.

Install systemd service for Stash

Stash provides a systemd service script. Download it to the correct location:

sudo wget -O /etc/systemd/system/stash.service https://gitstash.co/jcg/stash/raw/branch/stash/contrib/systemd/stash.service

If you’re not using sqlite, but MySQL or MariaDB or PostgreSQL, you’ll have to edit that file (/etc/systemd/system/stash.service) and uncomment the corresponding Wants= and After= lines. Otherwise it should work as it is.

After adding or modifying a systemd service file, you will need to reload systemd.

sudo systemctl daemon-reload

Now enable and start the Stash service, so you can go on with the installation:

sudo systemctl enable stash.service
sudo systemctl start stash.service

Stash’s web-based configuration

Access the Stash web UI by opening http://localhost:3000/ in your local web browser. Replace localhost with the server’s local IP address if necessary.

If it doesn’t work:

  • Make sure the stash service started successfully by checking the output of:
    sudo systemctl status stash.service
    If that indicates an error but the log lines underneath are too incomplete to tell what caused it,
    sudo journalctl -n 100 --unit stash.service
    will print the last 100 lines logged by Stash.

You should be greeted by Stash’s “Initial Configuration” screen. The settings should be mostly self-explanatory, some hints:

  • Select the correct database (SQLite3, or if you configured something else in the “Set up database” step above, select that and set the corresponding options)
  • Server Domain should be git.example.com (or whatever you’re actually using), Stash Base URL should be http://git.example.com:3000 (assuming you won’t change HTTP_PORT to a different value than 3000)
  • Check the Server and Third-Party Service Settings settings for settings that look relevant for you.
  • It may make sense to create the administrator account right now (Administrator Account Settings), even more so if you disabled self-registration.
  • Most settings can be changed in /etc/stash/app.ini later, so don’t worry about them too much.

Once you’re done configuring, click Install Stash and a few seconds later you should be on the dashboard (if you created an administrator account) or at the login/register screen, where you can create an account to then get to the dashboard.

So far, so good, but we’re not quite done yet - some manual configuration in the app.ini is needed.

Further configuration in Stash’s app.ini

Stop the stash service:

sudo systemctl stop stash.service

While at it, make /etc/stash/ and the app.ini read-only for the git user (Stash doesn’t write to it after the initial configuration):

sudo chmod 750 /etc/stash && sudo chmod 640 /etc/stash/app.ini

Now, (as root), edit /etc/stash/app.ini.

Note

You’ll probably find the Configuration Cheat Sheet and the Example app.ini that contains all options incl. descriptions helpful.

The following changes are recommended if dealing with many large files:

  • Stash allows uploading files to Git repositories through the web interface. By default the file size for uploads is limited to 3MB per file, and 5 files at once. To increase it, under the [repository] section, add a [repository.upload] section with a line like FILE_MAX_SIZE = 4095 (that would be 4095MB, about 4GB) and MAX FILES = 20 It’ll look somewhat like this:

    ...
    [repository]
    ROOT = /var/lib/stash/data/stash-repositories
    
    [repository.upload]
    ;; max size for files to the repo via web interface, in MB,
    ;; defaults to 3 (this sets a limit of about 4GB)
    FILE_MAX_SIZE = 4095
    ;; by default 5 files can be uploaded at once, increase to 20
    MAX_FILES = 20
    
    [server]
    ...

    Similar restrictions exist for attachments to issues/pull requests, configured in the [attachment] sections MAX_SIZE (default 4MB) and MAX_FILES (default 5) settings.

  • By default LFS data uploads expire after 20 minutes - this can be too short for big files, slow connections or slow LFS storage (git-lfs seems to automatically restart the upload then - which means that it can take forever and use lots of traffic).. If you’re going to use LFS with big uploads, increase thus limit, by adding the line LFS_HTTP_AUTH_EXPIRY = 180m (for 180 minutes) to the [server] section.

  • Similarly, there are timeouts for all kinds of git operations, that can be too short. Increasing all those git timeouts by adding a [git.timeout] section below the [server] section:

    ;; Git Operation timeout in seconds
    ;; increase the timeouts, so importing big repos (and presumably
    ;; pushing large files?) hopefully won't fail anymore
    [git.timeout]
    DEFAULT = 3600 ; Git operations default timeout seconds
    MIGRATE = 6000 ; Migrate external repositories timeout seconds
    MIRROR  = 3000 ; Mirror external repositories timeout seconds
    CLONE   = 3000 ; Git clone from internal repositories timeout seconds
    PULL    = 3000 ; Git pull from internal repositories timeout seconds
    GC      = 600  ; Git repository GC timeout seconds

    The example values are increased by a factor of 10 for illustration. Increasing all timeouts, particularly by this magnitude, may not be necessary. Evaluate your specific performance requirements and adjust values accordingly.

  • By default LFS files are stored in the filesystem, in /var/lib/stash/data/lfs. In the [lfs] section you can change the PATH = ... line to store elsewhere, but you can also configure Stash to store the files in an S3-like Object-Storage.

  • If you want to use the systemwide sendmail, enable sending E-Mails by changing the [mailer] section like this:

    [mailer]
    ;; send mail with systemwide "sendmail"
    ENABLED = true
    PROTOCOL = sendmail
    FROM = "Stash Git" <noreply@yourdomain.com>
  • By default, Stash will listen on the port 3000, but that can be changed to 80 with HTTP_PORT like this:

    [server]
    HTTP_PORT = 80

When you’re done editing the app.ini, save it and start the Stash service again:

sudo systemctl start stash.service

You can test sending a mail by clicking the user button on the upper right of the Stash page (“Profile and Settings”), then Site Administration, then Configuration and under Mailer Configuration type in your mail address and click Send Testing Email.

General hints for using Stash

Sometimes you may want/need to use the Stash command line interface. Keep in mind that:

  • You need to run it as the git user, for example with:
    $ sudo -u git stash command --argument
  • You need to specify the Stash work path, either with the --work-path /var/lib/stash (or -w /var/lib/stash) commandline option or by setting the STASH_WORK_DIR environment variable before calling stash:
    $ export STASH_WORK_DIR=/var/lib/stash
  • You need to specify the path to the config (app.ini) with either --config /etc/stash/app.ini or -c /etc/stash/app.ini.

So all in all your command might look like:

$ sudo -u git stash -w /var/lib/stash -c /etc/stash/app.ini admin user list

For convenience, you could create a /usr/local/bin/stash.sh with the following contents:

#!/bin/sh
sudo -u git stash -w /var/lib/stash -c /etc/stash/app.ini "$@"

and make it executable:

sudo chmod 755  /usr/local/bin/stash.sh

Now if you want to call stash on the commandline (for the default system-wide installation in /var/lib/stash), instead of the long line shown above, use:

$ stash.sh admin user list

You can always call stash and its subcommands with -h or --help to make it output usage information like available options and (sub)commands, for example to show available subcommands to administrate users on the commandline:

$ stash admin user -h