Skip to content

Deployment Guide

Jacob McSwain edited this page Feb 23, 2023 · 2 revisions

Configuring Prerequisites

DMRHub requires a PostgreSQL database and a Redis server for operation. The deployment of these is left as an exercise to the reader.

Setting up a PostgreSQL database and user for DMRHub

Connect to the database with psql (docs) and run the following commands. Make sure to change the changeme password below to a more appropriate secure password.

CREATE USER dmr WITH ENCRYPTED PASSWORD 'changeme';
CREATE DATABASE "dmr";
ALTER DATABASE dmr OWNER TO dmr;
GRANT ALL PRIVILEGES ON DATABASE dmr TO dmr;
\c dmr
GRANT ALL ON schema public TO dmr;

Running DMRHub

DMRHub has two avenues of release: a Docker image or a binary.

Docker releases

Docker images are published in GitHub here: https://github.com/USA-RedDragon/DMRHub/pkgs/container/dmrhub.

The Docker image supports the following architectures:

  • linux/amd64
  • linux/arm64
  • linux/arm/v7
  • linux/arm/v6

Docker images are based on golang:alpine. Tags are formed based on the Git tag. For example, v1.0.4 will be tagged ghcr.io/usa-reddragon/dmrhub:v1.0.4, :1.0.4, :1.0, and :1. Using a more generic tag, like :1 will allow users to grab the latest DMRHub version without having to manually pull in and run a new tag.

Running DMRHub with Docker

To run DMRHub, replace the -e ENVIRONMENT_VAR=value line in the following command with the environment variables required to configure the app. Multiple environment variables require multiple -e arguments before them. For example -e ENV1=val1 -e ENV2=val2.

sudo docker run \
    -d \
    --restart unless-stopped \
    -e ENVIRONMENT_VAR=value \
    -p 3005:3005 \
    -p 62031/udp:62031/udp \
    --name dmrhub \
    ghcr.io/usa-reddragon/dmrhub:1.0

To change the port mapping of DMRHub, replace the port number of the -p options before the : to the port you want DMRHub to listen on locally.

Binary releases

Binary releases are available at https://github.com/USA-RedDragon/DMRHub/releases. While many OS and architectures have releases, only Linux is officially supported. When running DMRHub on a different operating system, it is the deployer's responsibility to ensure the environment variables are appropriately provided to the DMRHub binary. Details of this process with SystemD are documented below.

Binaries are released for the following OS/architecture pairs:

  • linux/amd64
  • linux/386
  • linux/arm
  • linux/arm64
  • linux/riscv64
  • windows/386
  • windows/amd64
  • darwin/amd64
  • darwin/arm64
  • openbsd/arm
  • openbsd/amd64
  • openbsd/arm64
  • openbsd/386
  • netbsd/arm
  • netbsd/amd64
  • netbsd/arm64
  • netbsd/386
  • freebsd/riscv64
  • freebsd/arm
  • freebsd/amd64
  • freebsd/arm64
  • freebsd/386

Running on Linux with SystemD

This requires a bit more setup than the Docker option. A system user needs to be created to securely run DMRHub and the environment variables need to be placed in a file for SystemD to read and set for DMRHub.

Create a user, group, and directory dedicated to DMRHub

These commands create a dmrhub user and group, creates the /etc/dmrhub directory, and sets it's ownership to dmrhub where only the dmrhub user and group can read, write, and execute.

sudo mkdir /etc/dmrhub
sudo groupadd --system dmrhub
sudo useradd --home-dir /etc/dmrhub --no-create-home --no-user-group --system --shell /sbin/nologin dmrhub
sudo chown dmrhub:dmrhub /etc/dmrhub
sudo chmod 770 /etc/dmrhub

sudo mkdir /var/log/DMRHub
sudo chown dmrhub:dmrhub /var/log/DMRHub
sudo chmod 755 /var/log/DMRHub
Place DMRHub configuration environment variables

The following command will write all contents between the cat <<EOF line and the EOF line to /etc/dmrhub/env and sets the permission to only allow the dmrhub user and group to read and write this file. Alternatively, these environment variables can be added with a command line editor like nano.

cat <<EOF | sudo tee /etc/dmrhub/env
LISTEN_ADDR=0.0.0.0
...
EOF

sudo chown dmrhub:dmrhub /etc/dmrhub/env
sudo chmod 660 /etc/dmrhub/env
Copy DMRHub into the PATH

The following command copies DMRHub into /usr/local/bin so it can be executed.

sudo mv bin/DMRHub /usr/local/bin/
sudo chmod a+x /usr/local/bin/DMRHub
Install SystemD unit file

In the repository, there is a SystemD unit file that can be used for DMRHub. https://github.com/USA-RedDragon/DMRHub/blob/main/hack/dmrhub.service

Copy this file to the machine that will run DMRHub and copy it into /etc/systemd/system/ and activate it:

sudo cp hack/dmrhub.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now dmrhub.service
Viewing logs

Error can be viewed with journalctl -f -u dmrhub.service or via /var/log/DMRHub/DMRHub.error.log

Access logs can be viewed at /var/log/DMRHub/DMRHub.access.log