fix(install): use daemon user on OPNsense to survive reboots#1880

This commit is contained in:
Sven van Ginkel
2026-04-02 21:34:50 +02:00
committed by GitHub
parent e158a9001b
commit 77862d4cb1

View File

@@ -12,6 +12,10 @@ is_freebsd() {
[ "$(uname -s)" = "FreeBSD" ] [ "$(uname -s)" = "FreeBSD" ]
} }
is_opnsense() {
[ -f /usr/local/etc/opnsense-version ] || [ -f /etc/opnsense-release ]
}
is_glibc() { is_glibc() {
# Prefer glibc-enabled agent (NVML via purego) on linux/amd64 glibc systems. # Prefer glibc-enabled agent (NVML via purego) on linux/amd64 glibc systems.
# Check common dynamic loader paths first (fast + reliable). # Check common dynamic loader paths first (fast + reliable).
@@ -549,6 +553,7 @@ else
fi fi
# Create a dedicated user for the service if it doesn't exist # Create a dedicated user for the service if it doesn't exist
AGENT_USER="beszel"
echo "Configuring the dedicated user for the Beszel Agent service..." echo "Configuring the dedicated user for the Beszel Agent service..."
if is_alpine; then if is_alpine; then
if ! id -u beszel >/dev/null 2>&1; then if ! id -u beszel >/dev/null 2>&1; then
@@ -590,13 +595,18 @@ elif is_openwrt; then
fi fi
elif is_freebsd; then elif is_freebsd; then
if ! id -u beszel >/dev/null 2>&1; then if is_opnsense; then
pw user add beszel -d /nonexistent -s /usr/sbin/nologin -c "beszel user" echo "OPNsense detected: skipping user creation (using daemon user instead)"
fi AGENT_USER="daemon"
# Add the user to the wheel group to allow self-updates else
if pw group show wheel >/dev/null 2>&1; then if ! id -u beszel >/dev/null 2>&1; then
echo "Adding beszel to wheel group for self-updates" pw user add beszel -d /nonexistent -s /usr/sbin/nologin -c "beszel user"
pw group mod wheel -m beszel fi
# Add the user to the wheel group to allow self-updates
if pw group show wheel >/dev/null 2>&1; then
echo "Adding beszel to wheel group for self-updates"
pw group mod wheel -m beszel
fi
fi fi
else else
@@ -620,7 +630,7 @@ fi
if [ ! -d "$AGENT_DIR" ]; then if [ ! -d "$AGENT_DIR" ]; then
echo "Creating the directory for the Beszel Agent..." echo "Creating the directory for the Beszel Agent..."
mkdir -p "$AGENT_DIR" mkdir -p "$AGENT_DIR"
chown beszel:beszel "$AGENT_DIR" chown "${AGENT_USER}:${AGENT_USER}" "$AGENT_DIR"
chmod 755 "$AGENT_DIR" chmod 755 "$AGENT_DIR"
fi fi
@@ -899,7 +909,7 @@ TOKEN=$TOKEN
HUB_URL=$HUB_URL HUB_URL=$HUB_URL
EOF EOF
chmod 640 "$AGENT_DIR/env" chmod 640 "$AGENT_DIR/env"
chown root:beszel "$AGENT_DIR/env" chown "root:${AGENT_USER}" "$AGENT_DIR/env"
else else
echo "FreeBSD environment file already exists. Skipping creation." echo "FreeBSD environment file already exists. Skipping creation."
fi fi
@@ -917,6 +927,7 @@ EOF
# Enable and start the service # Enable and start the service
echo "Enabling and starting the agent service..." echo "Enabling and starting the agent service..."
sysrc beszel_agent_enable="YES" sysrc beszel_agent_enable="YES"
sysrc beszel_agent_user="${AGENT_USER}"
service beszel-agent restart service beszel-agent restart
# Check if service started successfully # Check if service started successfully