Troubleshooting & How-Tos 📡 🏷️ 🔍 Servers

Running Gophernicus on Alpine Linux

After using Gemini for more than 5 years, I finally decided to experiment with Gopher again.
The Gemini Protocol In Brief

Low End Box has a guide to running a Gopher server on a modern Linux server.
Running Gopher on a VPS

They recommend Gophernicus, partly because it’s available on Debian-based systems through apt. I wanted to add it to an existing Alpine Linux server, so I had to build it from source.
What I Like About Alpine Linux
Gophernicus

One snag: Gophernicus doesn’t listen to the network directly, it uses whatever network listener service the system provides. In the case of Linux, that’s usually systemd, inetd or xinetd. Alpine doesn’t ship with any of these. It uses OpenRC for running services instead of systemd.
OpenRC and Alpine Linux

Alpine does include inetd functionality in Busybox, if you add the busybox-extras package, and initialization scripts for it in busybox-extras-openrc.

doas apk add busybox-extras busybox-extras-openrc

Now you can build and install the gopher server.
Installing Gophernicus

./configure --listener=inetd
make
doas make install

Assuming no errors, you can either test it first by running doas inetd -f and trying to hit the site with a gopher client (or running netstat -lt and looking for gopher, or telnet localhost 70)…or go straight to setting up OpenRC to launch it at boot:

doas rc-update add inetd default
doas rc-service inetd start

Config changes

When I built Gophernicus, it generated an /etc/inetd.conf that was just right enough for inetd to pass requests to it, but just wrong enough that it didn’t recognize the options being passed to it.

Generated (wrong)

gopher	stream	tcp	nowait	nobody	//usr/local/sbin/gophernicus -h hostname.example.com -nv

Fixed /etc/inet.conf line, with additional options added:

gopher	stream	tcp	nowait	nobody	/usr/local/sbin/gophernicus	gophernicus -h hostname.example.com -nv -nu -r /path/to/my/gopher/files

I also found that simply reloading the inetd service wouldn’t pick up the changes. You have to restart it.

doas rc-service inetd restart

Firewall Config Using AWall

If you have a software firewall on your server (and you really should), you need to open up TCP port 70. If you’re using Alpine Wall (aka awall) to configure your firewall, you need to first tell it what port Gopher listens on, then tell it to allow incoming traffic to Gopher.

First, create (or edit) /etc/awall/private/custom-services.json

{
	"service": {
		/* you can define other services here if you want */
		"gopher": [
			{ "proto": "tcp", "port": 70 }
		]
	}
}

Next, create /etc/awall/optional/gopher.json

{
	"description": "Allow incoming Gopher on port 70",
	"import": [ "custom-services" ],
	"filter": [
		{
			"in": "internet",
			"out": "_fw",
			"service": [ "gopher"],
			"action": "accept"
		}
	]
}

Now enable it:

doas ln -s /etc/awall/optional/gopher.json /etc/awall/gopher.json

Activate the new firewall settings:

doas awall activate

You should be able to connect to the gopher server from outside now.

Directory Permissions

If you put your files somewhere other than the default /var/gopher, make sure that folder has read+execute permission for all, and every parent of that folder has execute permission.

chmod -R a+rX /path/to/gopher/stuff
chmod a+x /path/to/gopher
chmod a+x /path/to
chmod a+x /path

This includes user directories if you keep them enabled. They’ll live in public_gopher inside each home directory, and you’ll need to make your home directory and its parents executable.

That’s also why you need to hit each folder in the path instead of changing the top level recursively. You (or someone else) may have other folders inside the top one that shouldn’t be listable by just any process.

Ready to Dig

That should be enough to get you up and running. From then on it’s mainly just creating a folder structure with the files you want to serve. Custom menus are possible using gophermap files, which have a simple, but hard-to-remember and not-quite-legible format. Fortunately, Gophernicus includes an example you can work from.
README.gophermap

I’m still messing around with the structure and menus, and I’m not even sure how long I plan to keep it running, but you can see it at:
gopher://gopher.kvibber.com/