From cb2c7a10fd26a8a761f80aadd70621b5c021d1d7 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Mon, 23 Nov 2026 12:11:45 -0500 Subject: [PATCH 1/2] Docs: correct setup, workflow and scheduler reference, env vars, schema (#28) - Server setup: npm ci, .env from .env.example, /healthz check; no SECRET_KEY (nothing reads it). - Worker setup was wrong (worker.js lives in worker/, and the deps come from the root manifests): copy worker.js plus package.json and package-lock.json, npm ci --omit=dev, .env from worker/.env.example; updates then come through the worker deploy hook. - Workflows: replaces "Future Feature" with a reference for every step type and field, the condition language, params, goto/end, dry run, abort, webhooks and the time limit, with a worked example. New Scheduler section. - Environment variables: complete tables for server and worker, including GANDALF_API_KEY, EXECUTION_MAX_MINUTES, HOST, rate limits. - Database schema: the real tables and columns, scheduled_commands included. - Troubleshooting: stuck executions now fail on their own; how to clear. - Removed the stale "Recent Updates" and "Future Enhancements" lists. - .env.example and worker/.env.example; package.json license is MIT, like LICENSE. Co-Authored-By: Claude Opus 5.5 --- .env.example | 28 +++++ README.md | 269 ++++++++++++++++++++------------------------ package.json | 2 +- worker/.env.example | 10 ++ 4 files changed, 162 insertions(+), 147 deletions(-) create mode 100644 .env.example create mode 100644 worker/.env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..4996bbf --- /dev/null +++ b/.env.example @@ -0,0 +1,28 @@ +# PULSE server configuration. Copy to .env (chmod 600) and fill in. See README "Configuration". + +PORT=8080 +HOST=0.0.0.0 +NODE_ENV=production + +# MariaDB +DB_HOST= +DB_PORT=3306 +DB_NAME=pulse +DB_USER=pulse +DB_PASSWORD= + +# Reverse proxy that runs Authelia forward auth (only it may send identity headers) +TRUSTED_PROXIES= + +# Shared key the workers authenticate with; WORKER_AUTH_ENFORCE=1 refuses workers without it +WORKER_API_KEY= +WORKER_AUTH_ENFORCE=1 + +# Key for Gandalf's /api/internal calls (leave empty to disable them) +GANDALF_API_KEY= + +# Limits +EXECUTION_MAX_MINUTES=60 +EXECUTION_RETENTION_DAYS=30 +# PULSE_API_RATE_MAX=1000 +# PULSE_EXEC_RATE_MAX=20 diff --git a/README.md b/README.md index 3d958eb..2b690de 100644 --- a/README.md +++ b/README.md @@ -221,38 +221,14 @@ Lightweight execution agents that: ### PULSE Server Setup ```bash -# Clone repository cd /opt -git clone pulse-server +git clone https://code.lotusguild.org/LotusGuild/pulse.git pulse-server cd pulse-server +npm ci --omit=dev -# Install dependencies -npm install +cp .env.example .env # then fill in the values (see Configuration below) +chmod 600 .env -# Create .env file with configuration -cat > .env << EOF -# Server Configuration -PORT=8080 -SECRET_KEY=your-secret-key-here - -# MariaDB Configuration -DB_HOST=10.10.10.50 -DB_PORT=3306 -DB_NAME=pulse -DB_USER=pulse_user -DB_PASSWORD=your-db-password - -# Worker API Key (for worker authentication) -WORKER_API_KEY=your-worker-api-key - -# Reverse proxy that runs Authelia forward auth (required for SSO logins) -TRUSTED_PROXIES=192.0.2.10 - -# Auto-cleanup configuration (optional) -EXECUTION_RETENTION_DAYS=30 -EOF - -# Create systemd service cat > /etc/systemd/system/pulse.service << EOF [Unit] Description=PULSE Workflow Orchestration Server @@ -270,40 +246,31 @@ RestartSec=10 WantedBy=multi-user.target EOF -# Start service systemctl daemon-reload -systemctl enable pulse.service -systemctl start pulse.service +systemctl enable --now pulse.service +curl -s http://127.0.0.1:8080/healthz # {"status":"ok", ..., "db":true} ``` +The server creates its tables on first start. In production the unit file comes from +`jared/pve-infra` and code updates arrive through CI (see "Deploys"). + ### PULSE Worker Setup +A worker needs only `worker/worker.js` and the npm manifests from the repo root (its +dependencies are `axios`, `ws` and `dotenv`, which the root lockfile pins): + ```bash -# On each worker node -cd /opt -git clone pulse-worker -cd pulse-worker +mkdir -p /opt/pulse-worker && cd /opt/pulse-worker +# from a checkout of this repo: +cp /worker/worker.js /package.json /package-lock.json . +npm ci --omit=dev -# Install dependencies -npm install +cp /worker/.env.example .env # set WORKER_NAME, PULSE_SERVER, PULSE_WS, WORKER_API_KEY +chmod 600 .env -# Create .env file -cat > .env << EOF -# Worker Configuration -WORKER_NAME=pulse-worker-01 -PULSE_SERVER=http://10.10.10.65:8080 -PULSE_WS=ws://10.10.10.65:8080 -WORKER_API_KEY=your-worker-api-key - -# Performance Settings -HEARTBEAT_INTERVAL=30 -MAX_CONCURRENT_TASKS=5 -EOF - -# Create systemd service cat > /etc/systemd/system/pulse-worker.service << EOF [Unit] -Description=PULSE Worker Node +Description=PULSE Worker Agent After=network.target [Service] @@ -318,12 +285,14 @@ RestartSec=10 WantedBy=multi-user.target EOF -# Start service systemctl daemon-reload -systemctl enable pulse-worker.service -systemctl start pulse-worker.service +systemctl enable --now pulse-worker.service ``` +The worker appears on the Workers tab within a few seconds. Commands run as the service user +(root here). After the first install, updates are automatic: see "Worker deploys" for the hook +that lets CI install each new commit on the worker. + ## Usage ### Quick Command Execution @@ -362,13 +331,61 @@ The **Workers** tab displays real-time metrics for each worker: - **Clear Completed**: Bulk delete finished executions - **Auto-Cleanup**: Executions older than 30 days are automatically removed -### Workflow Creation (Future Feature) +### Workflows -1. Navigate to **Workflows** → **Create New** -2. Define workflow steps using JSON syntax -3. Specify target workers -4. Add interactive prompts where needed -5. Save and execute +A workflow is a JSON definition with a list of steps, created on the **Workflows** tab +(admin only) and started with **Execute**. Steps run in order unless one jumps elsewhere. + +```json +{ + "params": [{ "name": "host", "label": "Host", "required": true }], + "steps": [ + { "id": "probe", "type": "execute", "command": "ping -c 1 {{host}} >/dev/null && echo UP=yes || echo UP=no", "targets": ["node-01"] }, + { "id": "read", "type": "parse" }, + { "id": "decide", "type": "route", "conditions": [ + { "if": "state.up === 'yes'", "goto": "end", "label": "reachable" }, + { "default": true, "goto": "ask" } + ] }, + { "id": "ask", "type": "prompt", "message": "{{host}} is down. Restart its service?", "options": ["Restart", "Skip"], "routes": { "Skip": "end" } }, + { "id": "restart", "type": "execute", "command": "systemctl restart myservice", "targets": ["node-01"], "retries": 2 } + ] +} +``` + +| Step type | Fields | What it does | +|---|---|---| +| `execute` | `command`, `targets` (`["all"]` or worker names/ids; default all), `condition`, `timeout` (seconds, 5 to 600), `retries` (0 to 5), `retryDelayMs` | Runs the command on each target; a failure fails the workflow | +| `parse` | `condition` | Reads `KEY=VALUE` lines (key in capitals) from the last command's output into `state.key` (lower case) | +| `route` | `conditions`: `[{ "if", "goto", "label" }, { "default": true, "goto" }]` | Jumps to the first matching condition's step | +| `prompt` | `message`, `options`, `key`, `routes` (`{ "