Lemmy 0.16.7 on OpenBSD 7.2

Table of contents

Summary Summary

Lemmy (opens in a new tab) is one of Fediverse implementations, which focuses on link aggregators. It also works as a platform for forums and microblogging.

On technical aspects, used are Rust (opens in a new tab) Actix Web (opens in a new tab), an actor-model web framework good at concurrency, and InfernoJS (opens in a new tab), a blazingly fast client framework inspired by React (opens in a new tab). Therefore, it runs comfortably fast.

This post shows how to install Lemmy and configure it on OpenBSD (opens in a new tab), a solid operating system. As to Rust’s platform support, OpenBSD stands in Tier 3, the lowest in Target Tier Policy (opens in a new tab), and, however, it works !!

Environment Environment

Tutorial Tutorial

PostgreSQL PostgreSQL

Install PostgreSQL server and configure it (if undone) Install PostgreSQL server and configure it (if undone)

This post should help.

Create database Create database

Start psql (opens in a new tab):

console
$ psql -U <your-postgres-user>

Run to create role:

sql
create user lemmy with encrypted password '(...)';

The output was:

console
CREATE ROLE

Then run to create database belonging to the role:

sql
create database lemmy with owner lemmy \
    ENCODING 'UTF-8' template template0 LC_COLLATE 'C' LC_CTYPE 'C';

The output was:

console
CREATE DATABASE

MinIO (Optional) MinIO (Optional)

This post and its series may help.

Prepare Lemmy project Prepare Lemmy project

Suppose directories will be created as below:

/var
+-- /lemmy
    +-- /lemmy
    +-- /lemmy-ui
    +-- /pict-rs

Prepare Rust packages Prepare Rust packages

console
$ doas pkg_add rust

The output was:

console
quirks-6.42 signed on 2023-01-13T18:22:41Z
rust-1.63.0p0:libssh2-1.10.0p0: ok
rust-1.63.0p0: ok

Add a Lemmy user Add a Lemmy user

Run:

console
$ doas useradd -d /var/lemmy -m _lemmy

Then act as the user:

console
$ doas su - _lemmy

The login shell is perhaps ksh (opens in a new tab).

You must be in the home directory:

console
$ pwd
/var/lemmy

Lemmy server Lemmy server

This part is long so separated to another post. The following two are, too.

Go to this post and then return.

Lemmy-UI server Lemmy-UI server

Go to this post and return.

pict-rs server pict-rs server

Go to this post and return.

Build network Build network

The servers are ready !! Switch back to your own user (by executing exit).

Here is the final network archtecture in this post. All of Lemmy familly listen to lo, the internal network, only. relayd handles request/response between the external and the internal, including WebSocket (opens in a new tab) Lemmy-UI uses.

[external] <--> [internal]
                 relayd  <--> lemmy
                         <--> lemmy-ui
                              (websocket included)
                         <--> pict-rs

Be slightly careful about permissions of rc.d scripts.

Lemmy (server) Lemmy (server)

Create:

console
$ doas nvim /etc/rc.d/lemmy

to write in it:

sh
#!/bin/ksh

daemon="target/release/lemmy_server"
daemon_user="_lemmy"

daemon_execdir="/var/lemmy/lemmy"

. /etc/rc.d/rc.subr

rc_cmd $1

Lemmy-UI Lemmy-UI

Create:

console
$ doas nvim /etc/rc.d/lemmy_ui

to write in it:

sh
#!/bin/ksh

daemon="env LEMMY_UI_HOST=127.0.0.1:1234 LEMMY_INTERNAL_HOST=127.0.0.1:8536 LEMMY_EXTERNAL_HOST=<your-fqdb>:8536 LEMMY_WS_HOST=<your-fqdn>:443 node"
daemon_user="_lemmy"
daemon_flags="dist/js/server.js"

daemon_execdir="/var/lemmy/lemmy-ui"

. /etc/rc.d/rc.subr

rc_cmd $1

pict-rs pict-rs

Create:

console
$ doas nvim /etc/rc.d/lemmy_pict_rs

to write in it:

sh
#!/bin/ksh

daemon="target/release/pict-rs"
daemon_user="_lemmy"
daemon_flags="-c pict-rs.toml"

daemon_execdir="/var/lemmy/pict-rs"

. /etc/rc.d/rc.subr

rc_cmd $1

relayd.conf relayd.conf

Configuration about httpd (opens in a new tab) is optional. When you have other services in the same machine, you may have to do manage them.

apache
# $OpenBSD: relayd.conf,v 1.5 2018/05/06 20:56:55 benno Exp $

# prefork 5

#table <httpd> { "127.0.0.1" }
lemmy_server_port = "8536"
table <lemmy_ui> { "127.0.0.1" }
lemmy_ui_port = "1234"
table <lemmy_server> { "127.0.0.1" }
lemmy_server_port = "8536"

your_fqdn = "<your-fqdn>"

cert_keypair = "<cert-keypair-name>"

http protocol "https-filter" {
	return error

	#match request forward to <httpd>
	match request header "Host" value $your_fqdn forward to <lemmy_ui>
	match request url "<your-fqdn>/api/" forward to <lemmy_server>
	match request url "<your-fqdn>/pictrs/" forward to <lemmy_server>

	http websockets

	tls keypair $cert_keypair
}
relay "https-proxy" {
	listen on egress port https tls
	
	protocol "https-filter"

	#forward to <httpd> port http check tcp
	forward to <lemmy_ui> port $lemmy_ui_port check tcp
	forward to <lemmy_server> port $lemmy_server_port check tcp
}

http protocol "lemmy-server" {
	http websockets

	tls keypair $cert_keypair
}
relay "lemmy-server" {
	listen on $your_fqdn port $lemmy_server_port tls

	protocol "lemmy-server"

	forward to <lemmy_server> port $lemmy_server_port check tcp
}

Conclusion Conclusion

Let’s start the servers. Here are command lines to run them temporarily:

console
$ doas rcctl -f start {lemmy, lemmy_ui, lemmy_pict_rs, relayd}

* Besides, if you want to activate them, run rcctl enable beforehand, and -f option will be unnecessary.

Open your browser and access to <your-fqdn>. You will be welcomed.

lemmy-setup

After signing up, you will be guided to create an instance:

lemmy-instance-create-1

lemmy-instance-create-2

Then, voilà :)

lemmy-on-openbsd

Happy swimming across the fediverse.

More on: Run web, mail and federated services

OBSD Solutions

OBSD Solutions: OpenBSD consulting and support by Scqr, Reflerd Inc. (opens in a new tab)

Comments and feedback are welcome.