Lemmy 0.16.7 on OpenBSD 7.2
- Network services
- Published
- 5 min read
- @nabbisen
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
- OS: OpenBSD 7.2 (opens in a new tab)
- Database: PostgreSQL (opens in a new tab) 14.5 (opens in a new tab) (released on Aug 11, 2022)
- Object Storage: MinIO (opens in a new tab) - AWS (opens in a new tab) S3 (opens in a new tab)-compatible (Optional)
- Web Server: relayd (opens in a new tab)
- Apps
- Lemmy: 0.16.7
- based on Rust 1.63 (opens in a new tab) + Actix Web 4 (opens in a new tab) + Actix 0.13
- Lemmy-UI: 0.16.7
- based on InfernoJS 7.4
- Image hosting: pict-rs (opens in a new tab) 0.3.2
- Lemmy: 0.16.7
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):
$ psql -U <your-postgres-user>
Run to create role:
create user lemmy with encrypted password '(...)';The output was:
CREATE ROLE
Then run to create database belonging to the role:
create database lemmy with owner lemmy \
ENCODING 'UTF-8' template template0 LC_COLLATE 'C' LC_CTYPE 'C';The output was:
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
$ doas pkg_add rust
The output was:
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:
$ doas useradd -d /var/lemmy -m _lemmy
Then act as the user:
$ doas su - _lemmy
The login shell is perhaps ksh (opens in a new tab).
You must be in the home directory:
$ 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:
$ doas nvim /etc/rc.d/lemmy
to write in it:
#!/bin/ksh
daemon="target/release/lemmy_server"
daemon_user="_lemmy"
daemon_execdir="/var/lemmy/lemmy"
. /etc/rc.d/rc.subr
rc_cmd $1Lemmy-UI Lemmy-UI
Create:
$ doas nvim /etc/rc.d/lemmy_ui
to write in it:
#!/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 $1pict-rs pict-rs
Create:
$ doas nvim /etc/rc.d/lemmy_pict_rs
to write in it:
#!/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 $1relayd.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.
# $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:
$ 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.

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


Then, voilà :)

Happy swimming across the fediverse.
More on: Run web, mail and federated services
-
Tor 🧅 provides highly private access 👯 to the Web ✨
-
OpenBSD develops and maintains their own web server called “httpd” under ISC license.
-
This post is a part of Lemmy 0.16.7 on OpenBSD 7.2 about Lemmy.
OBSD Solutions
OBSD Solutions: OpenBSD consulting and support by Scqr, Reflerd Inc. (opens in a new tab)
Comments and feedback are welcome.