Running Gogs (Go Git Service) as a service on macOS X server

favicon.icoThis guides explains how you can run Gogs git server as a service on your Mac using launchd.

Command line tools

First you need to install Xcode from the Mac App Store. Once installed, you also need the Command Line Tools, you can initiate the download process by executing $ xcode-select --install in the Terminal.

The command line tools include Git.

MySQL or PostgreSQL server

You also need a database server for Gogs. You can install MySQL using MacPorts. A good tutorial can be found here.

You can alternatively run MariaDB instead of MySQL. My blogposts about MAMP (using MacPorts) includes a section about MariaDB.

Installing and configuring Gogs

I could try to write a good tutorial here, but the developers of Gogs already made a very nice tutorial about how you can install and configure Gogs. Read it here.

Launchd config

Create a launchd config file ~/Library/LaunchAgents/io.gogs.web.plist

<?xml version=”1.0" encoding=”UTF-8"?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN” “">
<plist version=”1.0">
            <string>cd /Users/mathias/Sites/gogs; ./gogs web</string>

You can now start and stop Gogs using the following commands:

$ launchctl load ~/Library/LaunchAgents/io.gogs.web.plist
$ launchctl unload ~/Library/LaunchAgents/io.gogs.web.plist

HTTPS proxy

I then run Caddy in front of Gogs to use Caddy’s built-in automated HTTPS support. My git subdomain is then a reverse proxy to Gogs: {
    proxy / http://localhost:3000

More info about running Caddy as a service can be found in this blogpost: Running Caddy as a service on macOS X server.