Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DEFAULT_GOAL := help

COMPONENTS := pull-config mie-opensource-landing create-a-container
COMPONENTS := agent mie-opensource-landing create-a-container
PACKAGER ?= deb

# Forwarded to every component Makefile.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Full documentation lives in [`mie-opensource-landing/docs/`](mie-opensource-land
| Path | Purpose |
|---|---|
| [`create-a-container/`](create-a-container/) | Manager web application (Node.js + Express + Sequelize) |
| [`pull-config/`](pull-config/) | Cron-driven config distribution for nginx and dnsmasq on agents — see [pull-config docs](mie-opensource-landing/docs/developers/pull-config.md) |
| [`agent/`](agent/) | Site agent: systemd-timer check-in that reports status and applies nginx/dnsmasq config — see [agent docs](mie-opensource-landing/docs/developers/agent.md) |
| [`images/`](images/) | Docker Bake definitions for the `base`, `nodejs`, `agent`, and `manager` images — see [Docker Images](mie-opensource-landing/docs/developers/docker-images.md) |
| [`manager-control-program/`](manager-control-program/) | MCP server for AI-assisted container management — see [MCP Server](mie-opensource-landing/docs/users/mcp-server.md) |
| [`mie-opensource-landing/`](mie-opensource-landing/) | Documentation site source |
Expand Down
6 changes: 3 additions & 3 deletions pull-config/.fpm → agent/.fpm
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
--vendor "Medical Informatics Engineering"
--url "https://github.com/mieweb/opensource-server"
--category admin
--description "MIE opensource-server edge agent (pull-config): cron-driven distribution of nginx and dnsmasq configuration to edge nodes. Also ships the static error pages referenced by the manager-rendered nginx config."
--description "MIE opensource-server site agent: checks in with the manager every 30 seconds, reports host and service status, and renders and applies nginx and dnsmasq configuration. Also ships the static error pages referenced by the rendered nginx config."
--depends nodejs
--depends nginx
--depends libnginx-mod-stream
--depends libnginx-mod-http-modsecurity
--depends modsecurity-crs
--depends ssl-cert
--depends dnsmasq
--depends curl
--depends cron
--deb-no-default-config-files
--after-install contrib/postinstall.sh
6 changes: 6 additions & 0 deletions agent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
.pkg/
*.deb
*.rpm
*.apk
38 changes: 25 additions & 13 deletions pull-config/Makefile → agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,56 @@

PREFIX ?= /opt/opensource-server
DESTDIR ?= /
DESTBIN := $(DESTDIR)$(PREFIX)/agent
UNIT_DIR := $(DESTDIR)/usr/lib/systemd/system

# Staging directory for packaging
STAGE := $(CURDIR)/.pkg/buildroot

INSTALL := install
INSTALL_DATA := $(INSTALL) -m 0644
INSTALL_PROG := $(INSTALL) -m 0755

ERROR_PAGES := ../error-pages

.PHONY: help deps build dev test install deb rpm apk package clean

help:
@echo "pull-config — builds the opensource-agent package."
@echo "agent — builds the opensource-agent package."
@echo ""
@echo "Targets:"
@echo " deps install dependencies (none; plain bash)"
@echo " build build the component (nothing to compile)"
@echo " test run tests (none; plain bash)"
@echo " deps install dependencies (npm ci)"
@echo " build compile the TypeScript sources"
@echo " test run tests (none yet)"
@echo " install stage files into DESTDIR (default /)"
@echo " deb build the .deb package"
@echo " rpm build the .rpm package"
@echo " apk build the .apk package"
@echo " clean remove the staging dir and built packages"
@echo " clean remove build output, staging dir and built packages"
@echo " help show this message"
@echo ""
@echo "Variables: PREFIX (default /opt/opensource-server), DESTDIR (default /)."

# Plain bash; nothing to install, compile, test, or watch.
deps:
npm ci

# Compile, then drop devDependencies so only the runtime node_modules
# (ejs) is staged into the package.
build: deps
dev: deps
npm run build
npm prune --omit=dev

dev: build

# No test suite yet; kept as a no-op so the repo-wide `make test` passes.
test:

install: build
$(INSTALL) -D -m 0755 bin/pull-config $(DESTDIR)$(PREFIX)/pull-config/bin/pull-config
$(INSTALL) -d $(DESTDIR)/etc/pull-config.d
$(INSTALL_PROG) etc/pull-config.d/* $(DESTDIR)/etc/pull-config.d/
$(INSTALL) -D -m 0644 etc/cron.d/pull-config $(DESTDIR)/etc/cron.d/pull-config
$(INSTALL) -d $(DESTBIN)
$(INSTALL_DATA) package.json $(DESTBIN)/
cp -a dist templates node_modules $(DESTBIN)/
$(INSTALL) -d $(UNIT_DIR)
$(INSTALL_DATA) contrib/systemd/opensource-agent.service $(UNIT_DIR)/
$(INSTALL_DATA) contrib/systemd/opensource-agent.timer $(UNIT_DIR)/
$(INSTALL) -d $(DESTDIR)$(PREFIX)/error-pages
$(INSTALL_DATA) $(ERROR_PAGES)/* $(DESTDIR)$(PREFIX)/error-pages/
$(INSTALL) -d -m 0755 $(DESTDIR)/var/cache/nginx/auth_cache
Expand All @@ -59,5 +71,5 @@ apk:
$(MAKE) package PACKAGER=apk

clean:
rm -rf $(STAGE)
rm -rf $(STAGE) node_modules dist
rm -f *.deb *.rpm *.apk
6 changes: 6 additions & 0 deletions agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# agent

Site agent for opensource-server. A oneshot Node.js script, launched every 30 seconds by a systemd timer, that checks in with the manager (`POST /api/v1/agents`), reports host and service status, and renders, tests and applies nginx and dnsmasq configuration from the returned snapshot.

- **Admin guide:** [Deploying Agents](https://mieweb.github.io/opensource-server/docs/admins/deploying-agents) — installation and configuration
- **Developer reference:** [agent](https://mieweb.github.io/opensource-server/docs/developers/agent) — check-in protocol, apply/rollback flow, managed services
19 changes: 19 additions & 0 deletions agent/contrib/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

UNITS="opensource-agent.timer"

# Nothing to do without systemctl (non-systemd container/chroot).
command -v systemctl >/dev/null 2>&1 || exit 0

# `systemctl enable` only creates static symlinks, so it works during an image
# build too
systemctl enable $UNITS

# daemon-reload and restart need a running systemd; skip them at build time.
if [ -d /run/systemd/system ]; then
systemctl daemon-reload
systemctl restart $UNITS
fi

exit 0
14 changes: 14 additions & 0 deletions agent/contrib/systemd/opensource-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=MIE opensource-server agent check-in
Wants=network-online.target
# environment.service (container images) writes the runtime env into
# /etc/environment; harmless ordering hint when the unit doesn't exist.
After=network-online.target environment.service

[Service]
Type=oneshot
# Runtime config (SITE_ID, MANAGER_URL, API_KEY) lives in /etc/environment.
EnvironmentFile=-/etc/environment
# systemd creates /var/lib/opensource-agent and passes it as $STATE_DIRECTORY.
StateDirectory=opensource-agent
ExecStart=/usr/bin/node /opt/opensource-server/agent/dist/index.js
10 changes: 10 additions & 0 deletions agent/contrib/systemd/opensource-agent.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Run the opensource-server agent check-in every 30 seconds

[Timer]
OnBootSec=30s
OnUnitActiveSec=30s
AccuracySec=1s

[Install]
WantedBy=timers.target
Loading
Loading