View on GitHub

gitblit-quickstart

Getting started with Gitblit - Configuring Gitblit as a service with runit

Download this project as a .zip file Download this project as a tar.gz file

Abstract

The purpose of this tutorial is to get you up and running with Gitbllit as quickly as possible. Gitblit is an open-source, pure Java stack for managing, viewing, and serving Git repositories. In this tutorial we will setup a stock Gitblit installation using runit for service management.

What You Will Learn

  1. How to install Gitblit
  2. How to setup runit to manage Gitblit

0. Prerequisites

Make sure that you java Java installed on your system. To verify that Java is installed execute the command:

# java -version

You should see some output that looks something like this:

java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1~deb7u1)
OpenJDK Client VM (build 23.7-b01, mixed mode, sharing)

If you see an error, consult the documentation on how to install Java for your platform.

Additionally, you will need runit installed. If you are unfamiliar with runit, you may want to read the following tutorial before continuing.

Getting started with the runit - a UNIX init scheme with service supervision

1. Installing Gitblit

The first thing that we need to do is create a user to run Gitblit with. Add a new user named gitblit using the method provided by your Linux distribution. For example, on Debain you can add the user with the the following command:

# adduser gitblit

Next, let's create a directory to install Gitblit in and change its ownership to the gitblit user. You can install Gitblit in any location you wish. I like to install it in the /opt directory.

# mkdir /opt/gitblit
# chown gitblit:gitblit /opt/gitblit

The only artifact that we need to install Gitbllit is the GO archive downloaded from the Gitblit Website.

Change to the gitblit user, navigate to the Gitblit installation directory, and download the zip. As of this writing the latest version is 1.3.2.

# su gitblit
# cd /opt/gitblit
# wget http://gitblit.googlecode.com/files/gitblit-1.3.2.zip

Gitblit is provided as an executable jar with an embedded web server. There is no need to deploy the war in a servlet container such as Tomcat.

By default Gitblit will only be available on the local server over SSL on port 8443. In order to access Gitblit from another server, we need to tell it to accept connections on interfaces besides localhost. If you would like to access Gitblit over a standard HTTP connection make the following changes in /opt/gitblit/data/gitblit.properties.

server.httpPort = 8080
server.httpBindInterface =

If you would like to access Gitblit over HTTPS then make the following changes in /opt/gitblit/data/gitblit.properties.

server.httpsPort = 8443
server.httpsBindInterface =

Start Gitblit by running the following command:

# java -jar gitblit.jar

You should see output displaying the progress of Gitblit starting up. Once it is started, open a web browser and navigate to port 8080 on your host, you should be greeted by the Gitblit home page. Take a few minutes to explore the application.

When you are done exploring Gitblit, go ahead and shut it down by entering Ctrl-c in the terminal.

2. Configuring runit to manage Gitblit

While the steps described above are great to fire up Gitblit and start exploring, when deploying Gitblit for use in production this simple approach has several issues. First, to ensure high availability of our git repository server we need a way to automate the management of the Gitblit process. Second, we need a way to manage logging. By configuring Gitblit as a managed service with runit, we can take care of both of these concerns.

If you are still acting as the gitblit user, revert back to root so that we can configure runit to monitor Gitblit.

First create a staging directory for our runit configuration by executing the following command :

# mkdir -p /etc/runit/gitblit

Create a script named run in the new directory with the following contents:

#!/bin/sh -e
cd /opt/gitblit
exec 2>&1
exec chpst -u gitblit java -jar gitblit.jar

Now make the script executable.

# chmod +x /etc/runit/gitblit/run

The only thing left to do is configure logging for the service. First create the logging configuration by making a log sub directory under /ect/runit/gitblit.

# mkdir /etc/runit/gitblit/log

Next, create a script named run in the log directory with the following contents:

#!/bin/sh
exec chpst -u gitblit svlogd -tt /opt/gitblit/logs

Make the script executable.

# chmod +x /etc/runit/gitblit/log/run

The /opt/gitblit/logs directory does not exit, so create it and change its ownership to the gitblit user.

# mkdir /opt/gitblit/logs
# chown gitblit:gitblit /opt/gitblit/logs

That is all of the configuration that we need to address process management and logging. Go ahead and deploy the service by creating a symbolic link from the /etc/service/gitblit directory to our staging directory.

# ln -s /etc/runit/gitblit /etc/service/gitblit

If everything worked, you should see information being written to the logs and Gitblit should be available on port 8080. Please take some time to review the basics of runit if you are not clear on what we just setup.

Start Commiting Code!!!

At this point you have everything you need to setup a monitored Gitblit server with logging. Your next step should be to read the Gitblit documentation to configure Gitblit to suit your needs. A good place to start is the "Gitblit Administration" page.

http://gitblit.com/administration.html

Contact Me

If you have any questions or would like further clarification, please feel free to shoot me an email. I would be glad to help.

Kevin

krchard@gmail.com