Anyone got Beszel working?

Started by allurbwrbelongtous, February 04, 2025, 02:55:31 PM

Previous topic - Next topic
Stumbled across this awesome system statistics utility that simply requires an executable be running on the device (or via docker) but I am not sure how to set it up on OPNsense.
Beszel - github

linux only. OPNsense is not based on linux but freeBSD so you need to ask them to provide you with an agent for freeBSD if you want to run it (presumably is what you want) on your OPN firewall.

February 04, 2025, 03:33:27 PM #2 Last Edit: February 04, 2025, 07:19:05 PM by Patrick M. Hausen
Quote from: cookiemonster on February 04, 2025, 03:08:41 PMlinux only. OPNsense is not based on linux but freeBSD so you need to ask them to provide you with an agent for freeBSD if you want to run it (presumably is what you want) on your OPN firewall.

Not quite Partly correct:

https://github.com/henrygd/beszel/releases/tag/v0.9.1

Quotebeszel-agent_freebsd_amd64.tar.gz

Since it is written in plain Golang, it should be easy to create an official port.

EDIT: this is only the agent. The hub/UI still needs to be run on Linux.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

right you are. I missed it in the quick scan of the release assets list.

Quote from: cookiemonster on February 04, 2025, 11:53:23 PMright you are. I missed it in the quick scan of the release assets list.

Any luck with this? I'd like to do this myself, wondering if you found a guide for setting it up as a service on freebsd.

I was only trying to gude the OP. Similarly for you, the asset list has what seems a binary asset, packaged in a tar.gz format. That if you are familiar with linux is a precompiled and compressed package. Inside it if it was linux there could be an rpm or deb package. You download it, decompress it and then proceed to install it with the distro (OS) usual tool. In freeBSD's case that is normally pkg. So you would do "#pkg install /path/to/uncompressed/package".
If it needs dependencies you have to resolve them of course.
Then proceed to configure it.
I don't need it/want it so haven't looked inside. These are broad strokes of what it would normally entail.

February 19, 2025, 02:14:06 PM #6 Last Edit: February 19, 2025, 02:15:52 PM by Arimil
I took a peek at it, seems it's just a binary was able to extract the agent and run it. Complained that I didn't have my `KEY` environment variable set. So seems to run just fine, would just need to do some manual work to set it up as a service.

It looks like their documentation has a guide for setting it up manually on linux (you'd be looking at step 2 not step 1):
https://beszel.dev/guide/agent-installation#binary

However their guide for setting up the service is using systemd, which would not work on freebsd so you'd have to read up on setting up a freebsd service and do that instead.

I'm not sure what the implications are of copying a binary to `/bin` on opnsense, I've never had to do it before and am unsure if such things will survive updates though.

Welp I set this up today here's a write up of what I did.

1. Download beszel_agent to `/usr/local/bin`
2. Create `beszel_agent` in `/usr/local/etc/rc.d/` with the following contents:
#!/bin/sh
#
# PROVIDE: beszel_agent
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# This script starts bezel-agent at system boot.
#
. /etc/rc.subr

name="beszel_agent"
rcvar=beszel_agent_enable

command="/usr/local/bin/beszel-agent"
command_args=""
pidfile="/var/run/${name}.pid"

load_rc_config $name
: ${beszel_agent_enable:="NO"}

# Ensure required environment variables are set.
if [ -z "${beszel_agent_key}" ] || [ -z "${beszel_agent_port}" ]; then
    echo "ERROR: beszel_agent_key and beszel_agent_port must be set in /etc/rc.conf.d/beszel_agent"
    exit 1
fi
beszel_agent_start() {
    echo "Starting beszel-agent..."
    # Launch the command with the required environment variables.
    env KEY="${beszel_agent_key}" PORT="${beszel_agent_port}" ${command} ${command_args} &
    echo $! > ${pidfile}
}

beszel_agent_stop() {
    echo "Stopping beszel-agent..."
    if [ -f ${pidfile} ]; then
        kill "$(cat ${pidfile})" && rm -f ${pidfile}
    fi
}

beszel_agent_status() {
    if [ -f "${pidfile}" ]; then
        pid=$(cat "${pidfile}")
        if kill -0 "${pid}" 2>/dev/null; then
            echo "beszel-agent is running (pid: ${pid})."
            return 0
        else
            echo "beszel-agent is not running (stale pid file)."
            return 1
        fi
    else
        echo "beszel-agent is not running."
        return 1
    fi
}

start_cmd="beszel_agent_start"
stop_cmd="beszel_agent_stop"
status_cmd="beszel_agent_status"

run_rc_command "$1"

3. Create `beszel_agent` in `/etc/rc.conf.d/` with the following contents:
beszel_agent_enable="YES"
beszel_agent_key=""
beszel_agent_port=""

4. Be sure to put the correct ssh key and port here given to you by beszel.
5. Run `service beszel_agent start`