Omega2 is a $5 micro-server. It comes with WiFi and SD card support but limited CPU power and RAM. I wanted to use it to host a private Git server for myself. I first looked at GitLab but it has some intense hosting requirements (like 2GB of RAM). That’s when I found Gogs, its a private Git hosting service written in Go. It doesn’t have any explicit requirements but its intended to be somewhat light.
I was finally able to set it up but I had some difficulties so I figured I should document it. There are three steps to setting up Gogs:
Cross Compile Gogs
Go comes with built in support for cross compiling. Here is a blog post that Omega’s documentation highlights on how to do it.
After setting up Go, it boils down to these commands to cross compile:
$ go get -u github.com/gogs/gogs
$ cd $GOPATH/src/github.com/gogs/gogs/
$ GOOS=linux GOARCH=mipsle go build
Note that this cross compiled build is not built withy any of the special
tags that gogs supports. In particular, this doesn’t build with sqlite3
support. Building with sqlite3 will required the CGO_ENABLED
flag which does
not support cross compiling.
Now we have a binary built for the MIPS architecture that Omega2 uses.
Now we can scp
the binary, the public
folder and the templates
folder to the Omega2.
Those two folders are needed for Gogs at runtime.
$ scp -r public root@omega-1234.local:/root/public
$ scp -r templates root@omega-1234.local:/root/templates
$ scp gogs root@omega-1234.local:/root/
Setting up Postgres
There are three steps to setting up Postgres on the Omega2:
Installing Postgres
Omega2 is based on the OpenWrt OS which supports Postgres but its not
available in the default package list. These feeds can be enabled by editing
/etc/opkg/distfeeds.conf
and uncommenting the other sources.
Once you do that Postgres should be available to install.
~# opkg list | grep pgsql
...
pgsql-cli - 9.6.8-1 - (CLI) to PostgreSQL databases.
pgsql-cli-extra - 9.6.8-1 - ...
pgsql-server - 9.6.8-1 - PostgreSQL databases Server.
...
You can run opkg install pgsql-server
to install the server (it will also install the cli).
Setting up Additional Swap Space
If you were to bring up a database on the Omega2 now, you would be greeted with this error:
FATAL: could not map anonymous shared memory: Out of memory
HINT: This error usually means that PostgreSQL's request for a
shared memory ...
request size (currently 39862272 bytes),
reduce PostgreSQL's shared memory usage, perhaps by
reducing shared_buffers or max_connections.
The issue is that Postgres tried to request a lot of memory on start up. Postgres’s config can be tuned to reduce the memory that is requested but I instead chose to create additional swap space since I had a lot of disk space available on the SD card.
Here is a link to omega2’s documentation that walks through setting up swap space.
Once you have the swap space set up and running, you are ready to bring up the database!
Bootstrapping the Database
By default, Postgres will create all the files for a database in the
/var/postgresql/data/
directory. Its likely that this directory doesn’t
have enough space. You can run df -h /var
to check where this folder is
mounted and how much space is available. You will likely want to set up a
folder to store the database on the external drive you are using. Since I
mounted my root folder on the external drive, that’s what I will use.
$ mkdir /root/pgdata
$ chmod 777 /root/pgdata
$ pg_ctl -D /root/pgdata -U postgres -l postgres.log init
This will initialize and bring up a database in the /root/pgdata
directory
as the Postgres user (this is why we needed to change permissions on the
directory to allow anyone to modify). Going forward, the database can be
brought up using pg_ctl -D /root/pgdata -U postgres -l postgres.log start
.
Similarly stop
can be used to stop the database.
Bring up and Install Gogs
We will create a new directory for repositories to be stored. Again, this should be on a mount with plenty of space.
$ mkdir /root/gogs_repositories
$ chmod 777 /root/gogs_repositories
Now you are ready to bring up gogs with ./gogs web
on the Omega2. This will bring up
the gogs website on port 3000.
If you go to this website in your browser by going to http://omega-####.local:3000
, the website
will take you to a “setup” page to configure gogs.
In this screen, you can choose Postgres as the database type and postgres
as the user and the database name.
You can leave the password entry empty.
The repo root path should be set to the directory created above. I chose the user to be run as as postgres
as well.
You can look at other settings as well, but most likely you will not need to configure them. Once you submit,
you may get an errors but gogs
has pretty great error messages that explains exactly what’s wrong.
Once you are done with this step, you will just have to register a user. The first user that is registered will also have admin access.
Now you should be able to push through all the personal repos you want!