Installing Gogs In A FreeNAS Jail

Installing Gogs In A FreeNAS Jail

I recently stumbled across the Gogs project whilst looking for self-hosted Git solutions. I run a FreeNAS server at home so I thought I would get the app up and running in a jail. Here is how I did it.

Jail Preparation

Create a new jail named gogs and make sure that the jail is up to date by running.

pkg update && pkg upgrade

Now install the required packages.

pkg install go git gcc

Next add a user git and switch to the new user.

pw useradd git -m
su git -

Set the Go env variables both for this session and for future sessions.

GOPATH=$HOME/go; export GOPATH
echo 'GOPATH=$HOME/go; export GOPATH' >> ~/.profile

Installation and Initial Configuration

Fetch Gogs using the Go package manager.

go get -u --tags sqlite github.com/gogs/gogs

Create a symbolic link to the gogs directory to make it easier to manage.

ln -s ~/go/src/github.com/gogs/gogs ~/gogs

cd into the source directory and issue the build command.

cd ~/gogs
go build --tags sqlite

Issue the following command to start gogs for the first time and then browse to the jails IP address at port 3000 and complete the initial configuration via the web GUI.

./gogs web

Once you have completed the installation terminate the gogs process from the terminal using Ctrl+C.

Finally, we need to switch back to the root user and configure an init script to set the gogs service to start at boot.

exit
cp /home/git/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/
chmod a+x /usr/local/etc/rc.d/gogs

We also need to add gogs_enable="YES" to the /etc/rc.conf file. Now we can start the service and test that it is working via a web browser.

service gogs start

Updating

Updating is a piece of cake! But take a jail snapshot first!!!!

SSH into the gogs jail and run the following commands.

su git
cd /home/git/gogs
go get -u --tags sqlite github.com/gogs/gogs
go build --tags sqlite
exit
service gogs start
×