From ca8b001991e3bfe65d25b7539b29d350a546759e Mon Sep 17 00:00:00 2001 From: benya Date: Fri, 5 Jun 2026 13:54:43 +0300 Subject: [PATCH] Add Go agent OpenWrt service package --- agent/README.md | 19 ++++++++- agent/openwrt/rmm-agent-go.conf | 12 ++++++ agent/openwrt/rmm-agent-go.init | 23 +++++++++++ agent/package/rmm-agent-go/Makefile | 40 +++++++++++++++++++ agent/package/rmm-agent-go/README.md | 37 +++++++++++++++++ .../files/etc/init.d/rmm-agent-go | 23 +++++++++++ .../rmm-agent-go/files/etc/rmm-agent-go.conf | 12 ++++++ 7 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 agent/openwrt/rmm-agent-go.conf create mode 100644 agent/openwrt/rmm-agent-go.init create mode 100644 agent/package/rmm-agent-go/Makefile create mode 100644 agent/package/rmm-agent-go/README.md create mode 100644 agent/package/rmm-agent-go/files/etc/init.d/rmm-agent-go create mode 100644 agent/package/rmm-agent-go/files/etc/rmm-agent-go.conf diff --git a/agent/README.md b/agent/README.md index ce28f71..cbc87cc 100644 --- a/agent/README.md +++ b/agent/README.md @@ -103,14 +103,31 @@ EOF ./tmp/rmm-agent-go -config /etc/rmm-agent-go.conf -once ``` +Side-by-side procd service: + +```sh +cp ./tmp/rmm-agent-go /usr/bin/rmm-agent-go +chmod +x /usr/bin/rmm-agent-go +cp ./agent/openwrt/rmm-agent-go.init /etc/init.d/rmm-agent-go +chmod +x /etc/init.d/rmm-agent-go +cp ./agent/openwrt/rmm-agent-go.conf /etc/rmm-agent-go.conf +vi /etc/rmm-agent-go.conf +/etc/init.d/rmm-agent-go enable +/etc/init.d/rmm-agent-go start +``` + +The side-by-side service uses `/etc/rmm-agent-go.conf`, `/tmp/rmm-agent-go.lock`, `/tmp/rmm-agent-go-results`, `/tmp/rmm-agent-go-backups`, and `/tmp/rmm-agent-go-tunnels` so it does not collide with the shell agent. + ## OpenWrt Package Package skeleton: ```text agent/package/rmm-agent +agent/package/rmm-agent-go ``` -It installs the agent as `/usr/bin/rmm-agent`, the procd service as `/etc/init.d/rmm-agent`, and the default config as `/etc/rmm-agent.conf`. +The shell package installs `/usr/bin/rmm-agent`, `/etc/init.d/rmm-agent`, and `/etc/rmm-agent.conf`. +The Go package installs `/usr/bin/rmm-agent-go`, `/etc/init.d/rmm-agent-go`, and `/etc/rmm-agent-go.conf`. For Docker Compose reverse SSH access, install the generated tunnel private key at `/etc/rmm-agent/tunnel_key` with mode `600`. The agent automatically uses it for `remote_ssh_reverse`. diff --git a/agent/openwrt/rmm-agent-go.conf b/agent/openwrt/rmm-agent-go.conf new file mode 100644 index 0000000..6329e12 --- /dev/null +++ b/agent/openwrt/rmm-agent-go.conf @@ -0,0 +1,12 @@ +SERVER_URL="http://127.0.0.1:8080" +ENROLLMENT_TOKEN="dev-enroll-token" +INTERVAL_SECONDS="30" +CHECK_TARGETS="1.1.1.1 8.8.8.8" +TUNNEL_IDENTITY_FILE="/etc/rmm-agent/tunnel_key" +LOCK_FILE="/tmp/rmm-agent-go.lock" +SPOOL_DIR="/tmp/rmm-agent-go-results" +BACKUP_DIR="/tmp/rmm-agent-go-backups" +TUNNEL_STATE_DIR="/tmp/rmm-agent-go-tunnels" +HOSTNAME_SUFFIX="-go" +DEVICE_ID="" +DEVICE_TOKEN="" diff --git a/agent/openwrt/rmm-agent-go.init b/agent/openwrt/rmm-agent-go.init new file mode 100644 index 0000000..abc0aa0 --- /dev/null +++ b/agent/openwrt/rmm-agent-go.init @@ -0,0 +1,23 @@ +#!/bin/sh /etc/rc.common + +START=95 +STOP=10 +USE_PROCD=1 + +PROG=/usr/bin/rmm-agent-go +CONFIG_FILE=/etc/rmm-agent-go.conf + +start_service() { + procd_open_instance + procd_set_param command "$PROG" -config "$CONFIG_FILE" + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param term_timeout 15 + procd_set_param respawn 3600 5 5 + procd_close_instance +} + +stop_service() { + service_stop "$PROG" + rm -rf /tmp/rmm-agent-go.lock +} diff --git a/agent/package/rmm-agent-go/Makefile b/agent/package/rmm-agent-go/Makefile new file mode 100644 index 0000000..1c475db --- /dev/null +++ b/agent/package/rmm-agent-go/Makefile @@ -0,0 +1,40 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=rmm-agent-go +PKG_VERSION:=0.5.0 +PKG_RELEASE:=1 + +PKG_MAINTAINER:=RMM OpenWrt +PKG_LICENSE:=MIT + +include $(INCLUDE_DIR)/package.mk + +define Package/rmm-agent-go + SECTION:=admin + CATEGORY:=Administration + TITLE:=OpenWrt RMM Go agent + DEPENDS:=+ca-bundle +ip-tiny +iwinfo +openssh-client +openssh-keygen +endef + +define Package/rmm-agent-go/description + Go implementation of the outbound polling agent for OpenWrt RMM. +endef + +define Build/Compile + [ -x ./files/usr/bin/rmm-agent-go ] +endef + +define Package/rmm-agent-go/conffiles +/etc/rmm-agent-go.conf +endef + +define Package/rmm-agent-go/install + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) ./files/usr/bin/rmm-agent-go $(1)/usr/bin/rmm-agent-go + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/etc/init.d/rmm-agent-go $(1)/etc/init.d/rmm-agent-go + $(INSTALL_DIR) $(1)/etc + $(INSTALL_CONF) ./files/etc/rmm-agent-go.conf $(1)/etc/rmm-agent-go.conf +endef + +$(eval $(call BuildPackage,rmm-agent-go)) diff --git a/agent/package/rmm-agent-go/README.md b/agent/package/rmm-agent-go/README.md new file mode 100644 index 0000000..cd26ea6 --- /dev/null +++ b/agent/package/rmm-agent-go/README.md @@ -0,0 +1,37 @@ +# rmm-agent-go OpenWrt Package + +OpenWrt package skeleton for the Go agent. + +## Buildroot Usage + +Cross-build the Go binary for the router target first and place it into the package-local files directory: + +```sh +mkdir -p agent/package/rmm-agent-go/files/usr/bin +GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -trimpath -ldflags="-s -w" -o agent/package/rmm-agent-go/files/usr/bin/rmm-agent-go ./agent/go/cmd/rmm-agent +``` + +Copy or symlink this directory into an OpenWrt buildroot package path: + +```sh +cp -R agent/package/rmm-agent-go /path/to/openwrt/package/rmm-agent-go +cd /path/to/openwrt +make package/rmm-agent-go/compile V=s +``` + +Then install the generated `.ipk` on a router: + +```sh +opkg install /tmp/rmm-agent-go_*.ipk +vi /etc/rmm-agent-go.conf +/etc/init.d/rmm-agent-go enable +/etc/init.d/rmm-agent-go start +``` + +## Installed Files + +- `/usr/bin/rmm-agent-go` +- `/etc/init.d/rmm-agent-go` +- `/etc/rmm-agent-go.conf` + +The package intentionally keeps a separate config and service name so it can run side by side with the shell agent during migration. diff --git a/agent/package/rmm-agent-go/files/etc/init.d/rmm-agent-go b/agent/package/rmm-agent-go/files/etc/init.d/rmm-agent-go new file mode 100644 index 0000000..abc0aa0 --- /dev/null +++ b/agent/package/rmm-agent-go/files/etc/init.d/rmm-agent-go @@ -0,0 +1,23 @@ +#!/bin/sh /etc/rc.common + +START=95 +STOP=10 +USE_PROCD=1 + +PROG=/usr/bin/rmm-agent-go +CONFIG_FILE=/etc/rmm-agent-go.conf + +start_service() { + procd_open_instance + procd_set_param command "$PROG" -config "$CONFIG_FILE" + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param term_timeout 15 + procd_set_param respawn 3600 5 5 + procd_close_instance +} + +stop_service() { + service_stop "$PROG" + rm -rf /tmp/rmm-agent-go.lock +} diff --git a/agent/package/rmm-agent-go/files/etc/rmm-agent-go.conf b/agent/package/rmm-agent-go/files/etc/rmm-agent-go.conf new file mode 100644 index 0000000..6329e12 --- /dev/null +++ b/agent/package/rmm-agent-go/files/etc/rmm-agent-go.conf @@ -0,0 +1,12 @@ +SERVER_URL="http://127.0.0.1:8080" +ENROLLMENT_TOKEN="dev-enroll-token" +INTERVAL_SECONDS="30" +CHECK_TARGETS="1.1.1.1 8.8.8.8" +TUNNEL_IDENTITY_FILE="/etc/rmm-agent/tunnel_key" +LOCK_FILE="/tmp/rmm-agent-go.lock" +SPOOL_DIR="/tmp/rmm-agent-go-results" +BACKUP_DIR="/tmp/rmm-agent-go-backups" +TUNNEL_STATE_DIR="/tmp/rmm-agent-go-tunnels" +HOSTNAME_SUFFIX="-go" +DEVICE_ID="" +DEVICE_TOKEN=""