lapthorn.net *this.that(&theOther);

Raspberry Pi as a git server

This is taken verbatim from Alex Tavendale’s instructions. This worked first time for me, and the only additional steps I had to perform were to get gogs configured to have non localhost DNS name for the rest of my network, otherwise the gogs installation was only accessible directly from the pi.

I’ve copied the original steps here here, so I don’t lose the steps.

I’d like to swap out supervisor for perp, but I’ll leave that for another time.

STEP 1 – INSTALL MYSQL

Start by checking the pi is updated:

 sudo apt-get update

Next install MySQL (the -y flag assumes yes to all prompts)

 sudo apt-get -y install mysql-server

During the install it will ask for a password. Use a secure password and remember it as we will need it later. Next create a file named gogs.sql

vim gogs.sql

Then paste the following text, then save and close the document:

DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;

Next you need to execute this code by running and replacing your_password with the password you entered while installing MySQL:

mysql -u root -pyour_password < gogs.sql

Note: there is no space between the -p and your password

STEP 2 – INSTALLING GO

DOWNLOAD

Go is the language Gogs is written in and needs to be installed before we can install Gogs. First create a new user which will be used for install and setup, and will later be used to run Gogs:

sudo adduser --disabled-login --gecos 'Gogs' git

Then switch to this user:

sudo su - git

Change to the home directory:

cd ~

Create a new directory to install Gogs to:

mkdir local

Then we need to download Go for ARM. For the latest version go to http://dave.cheney.net/unofficial-arm-tarballs and get the link to the latest version. At the time of writing it is 1.4.2 so I will use that in this guide, but use a newer version if available.

Note: If you are following this tutorial on an Intel or AMD machine (NOT a Raspberry Pi) then you will need to get the official version of Go from https://golang.org/

Download Go to your Pi by entering (replace the file URL if a newer version is available):

wget http://dave.cheney.net/paste/go1.4.2.linux-arm~multiarch-armv6-1.tar.gz

Then expand this to the local directory

tar -C /home/git/local -xzf go1.4.2.linux-arm~multiarch-armv6-1.tar.gz

SETUP

Run the following commands to setup Go:

echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc
echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc

These commands add Go paths to your .bashrc file before reloading the file.

STEP 3 – INSTALL GOGS

Run these commands to download and install the latest version of Gogs:

go get -u github.com/gogits/gogs
cd $GOPATH/src/github.com/gogits/gogs
go build

STEP 4 – INSTALL SUPERVISOR

Next we will install Supervisor to manage Gogs

First, logout the git account by entering

exit

Then install Supervisor using:

sudo apt-get -y install supervisor

Next, create a directory for the log files:

sudo mkdir -p /var/log/gogs

Open the Supervisor config:

sudo nano /etc/supervisor/supervisord.conf

Add the following text to the bottom of the file which will automatically run Gogs:

[program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"

Now restart Supervisor:

sudo service supervisor restart

To verify the server is running, enter:

tail /var/log/gogs/stdout.log

You should see a line like this:

2015/03/25 20:00:42 [I] Gogs: Go Git Service 0.6.1.0325 Beta

You should also be able to visit http://your_server_ip:3000 which will redirect you to the install page, but do not fill this out yet

STEP 5 – SETUP NGINX

This step is optional, but recommended as it will allow you to access Gogs by going to http://your_server_ip without the port.

First, install Nginx:

sudo apt-get -y install nginx

Create a config file for Gogs:

sudo nano /etc/nginx/sites-available/gogs

Paste the following into the file:

server {
    listen 80;
    server_name your_server_ip;

    proxy_set_header X-Real-IP  $remote_addr; # pass on real client IP

    location / {
        proxy_pass http://localhost:3000;
    }
}

Symlink it:

sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs

Restart Nginx:

sudo service nginx restart

Finally, visit your server ip to configure Gogs.

© 2017   lapthorn.net