Merge pull request 'Docs: correct setup, workflow and scheduler reference, env vars, schema' (#73) from docs-refresh into main
CI / UI screenshots (before/after) (push) Skipped
CI / Test (jest) (push) Successful in 27s
CI / Lint (eslint) (push) Successful in 30s
CI / Security (npm audit) (push) Successful in 19s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m0s
CI / Integration (api) (push) Successful in 2m37s
CI / UI (playwright) (push) Successful in 1m38s
CI / Deploy (push) Successful in 14s
CI / Deploy worker (push) Successful in 21s
CI / Notify (push) Successful in 4s
CI / UI screenshots (before/after) (push) Skipped
CI / Test (jest) (push) Successful in 27s
CI / Lint (eslint) (push) Successful in 30s
CI / Security (npm audit) (push) Successful in 19s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m0s
CI / Integration (api) (push) Successful in 2m37s
CI / UI (playwright) (push) Successful in 1m38s
CI / Deploy (push) Successful in 14s
CI / Deploy worker (push) Successful in 21s
CI / Notify (push) Successful in 4s
This commit was merged in pull request #73.
This commit is contained in:
commit
06d6c72709
5 files changed
+169
-148
No files matched your search
@@ -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
|
||||
@@ -221,38 +221,14 @@ Lightweight execution agents that:
|
||||
### PULSE Server Setup
|
||||
|
||||
```bash
|
||||
# Clone repository
|
||||
cd /opt
|
||||
git clone <your-repo-url> 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 <your-repo-url> pulse-worker
|
||||
cd pulse-worker
|
||||
mkdir -p /opt/pulse-worker && cd /opt/pulse-worker
|
||||
# from a checkout of this repo:
|
||||
cp <repo>/worker/worker.js <repo>/package.json <repo>/package-lock.json .
|
||||
npm ci --omit=dev
|
||||
|
||||
# Install dependencies
|
||||
npm install
|
||||
cp <repo>/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` (`{ "<option>": "<step id>" }`) | Waits for someone to answer in the UI (up to 60 min, never past the execution's time limit). An unanswered prompt fails the workflow |
|
||||
| `wait` | `duration` (seconds) | Pauses, never past the execution's time limit |
|
||||
|
||||
Any step can have `goto: "<step id>"` or `goto: "end"`. Ids must be unique, and every goto
|
||||
must name an existing step: saving a workflow checks this.
|
||||
|
||||
**Conditions** (`condition`, route `if`) are expressions over `state.*` (values from `parse`
|
||||
and prompt answers), `params.*` and `promptResponse`: comparisons (`=== !== < > <= >=`),
|
||||
`&& || !`, arithmetic, `parseInt`, `parseFloat`, `Number`, `String`, `Boolean`, and the string
|
||||
methods `trim`, `toLowerCase`, `toUpperCase`, `includes`, `startsWith`, `endsWith`. They are
|
||||
evaluated by a small interpreter (`lib/condition.js`), never as JavaScript, and a condition
|
||||
that doesn't parse is rejected when the workflow is saved.
|
||||
|
||||
**Parameters** (`params`) are asked for when the workflow starts and substituted into
|
||||
commands as `{{name}}`. Values may only contain letters, digits and `. _ : @ / -`.
|
||||
|
||||
**Dry run** logs each command without running it. **Abort** stops the workflow before its
|
||||
next step and kills its running commands on the workers. A workflow can have a `webhook_url`:
|
||||
Pulse POSTs `{execution_id, workflow_id, workflow_name, status, started_by, started_at,
|
||||
completed_at}` to it when the execution completes or fails. The whole execution is limited to
|
||||
`EXECUTION_MAX_MINUTES` (default 60).
|
||||
|
||||
### Scheduler
|
||||
|
||||
The **Scheduler** tab (admin only) runs a command on chosen workers on a schedule:
|
||||
`interval` (every N minutes), `hourly` (every N hours), `daily` (`HH:MM`) or `cron` (a cron
|
||||
expression). Each run is an execution started by `scheduler:<name>`. A run whose worker is
|
||||
offline is recorded as failed ("Worker offline"), and a schedule whose previous run is still
|
||||
going is skipped.
|
||||
|
||||
## Features in Detail
|
||||
|
||||
@@ -399,7 +416,7 @@ The **Workers** tab displays real-time metrics for each worker:
|
||||
- Authelia SSO integration for user authentication, with identity headers only accepted from `TRUSTED_PROXIES`
|
||||
- API key authentication for workers
|
||||
- User session management
|
||||
- Admin-only operations (worker deletion, workflow management)
|
||||
- Admin-only: Pulse admits only the Authelia `admin` group
|
||||
- Audit logging for all executions
|
||||
|
||||
### Performance
|
||||
@@ -413,27 +430,36 @@ The **Workers** tab displays real-time metrics for each worker:
|
||||
|
||||
### Environment Variables
|
||||
|
||||
**Server (.env):**
|
||||
```bash
|
||||
PORT=8080 # Server port
|
||||
SECRET_KEY=<random-string> # Session secret
|
||||
DB_HOST=10.10.10.50 # MariaDB host
|
||||
DB_PORT=3306 # MariaDB port
|
||||
DB_NAME=pulse # Database name
|
||||
DB_USER=pulse_user # Database user
|
||||
DB_PASSWORD=<password> # Database password
|
||||
WORKER_API_KEY=<api-key> # Worker authentication key
|
||||
TRUSTED_PROXIES=<ip>[,<ip/cidr>] # Proxies allowed to send Authelia identity headers (required, see below)
|
||||
WORKER_AUTH_ENFORCE=1 # Refuse workers that don't send WORKER_API_KEY (see WebSocket authentication)
|
||||
EXECUTION_RETENTION_DAYS=30 # Auto-cleanup retention (default: 30)
|
||||
**Server (.env):** `.env.example` lists them all.
|
||||
|
||||
# Web UI (all optional)
|
||||
APP_NAME=PULSE # Header/boot/title app name (default: PULSE)
|
||||
APP_SUBTITLE=<text> # Header subtitle (default: "Worker Orchestration // LotusGuild")
|
||||
PULSE_CSP_REPORT_ONLY=1 # Serve the CSP report-only instead of enforcing it
|
||||
PULSE_DEV_READONLY=1 # Local dev guard: disable all background writes (see below)
|
||||
DISABLE_BACKGROUND_JOBS=1 # Alias for PULSE_DEV_READONLY
|
||||
```
|
||||
| Variable | Default | Purpose |
|
||||
|---|---|---|
|
||||
| `PORT`, `HOST` | `8080`, `0.0.0.0` | Where the server listens |
|
||||
| `DB_HOST`, `DB_PORT`, `DB_NAME`, `DB_USER`, `DB_PASSWORD` | (required) | MariaDB connection |
|
||||
| `TRUSTED_PROXIES` | (required) | Proxies allowed to send Authelia identity headers (see below) |
|
||||
| `WORKER_API_KEY` | (required) | Shared key workers authenticate with |
|
||||
| `WORKER_AUTH_ENFORCE` | off | `1` refuses workers that don't send the key (see below) |
|
||||
| `GANDALF_API_KEY` | (none) | Key for Gandalf's `/api/internal/*` calls; unset disables them |
|
||||
| `EXECUTION_MAX_MINUTES` | `60` | Time limit for a workflow execution |
|
||||
| `EXECUTION_RETENTION_DAYS` | `30` | Executions older than this are deleted |
|
||||
| `PULSE_API_RATE_MAX`, `PULSE_EXEC_RATE_MAX` | `1000` per 15 min, `20` per min | Rate limits per signed-in user (and for Gandalf) |
|
||||
| `APP_NAME`, `APP_SUBTITLE` | `PULSE`, `Worker Orchestration // LotusGuild` | Branding |
|
||||
| `PULSE_CSP_REPORT_ONLY` | off | `1` reports CSP violations instead of enforcing |
|
||||
| `PULSE_DEV_READONLY` (alias `DISABLE_BACKGROUND_JOBS`) | off | Local dev guard: no background writes (see below) |
|
||||
| `NODE_ENV` | | `production` in production |
|
||||
|
||||
Test stacks only (`scripts/ci/ui-stack.sh` sets them): `PULSE_SCHEDULER_TICK_MS`,
|
||||
`PULSE_PROMPT_TIMEOUT_MS`.
|
||||
|
||||
**Worker (.env):** `worker/.env.example`.
|
||||
|
||||
| Variable | Default | Purpose |
|
||||
|---|---|---|
|
||||
| `WORKER_NAME` | hostname | Name shown in Pulse; must be unique |
|
||||
| `PULSE_SERVER`, `PULSE_WS` | `http://localhost:8080`, `ws://localhost:8080` | Server URLs |
|
||||
| `WORKER_API_KEY` | (required) | Same value as the server's |
|
||||
| `HEARTBEAT_INTERVAL` | `30` | Seconds between heartbeats |
|
||||
| `MAX_CONCURRENT_TASKS` | `5` | Commands run at once; more are refused with an error |
|
||||
|
||||
### Trusted proxies
|
||||
|
||||
@@ -491,36 +517,15 @@ MAX_CONCURRENT_TASKS=5 # Max parallel tasks (default: 5)
|
||||
|
||||
## Database Schema
|
||||
|
||||
PULSE uses MariaDB with the following tables:
|
||||
The server creates these tables in MariaDB on start:
|
||||
|
||||
| Table | Purpose |
|
||||
|-------|---------|
|
||||
| `users` | User accounts synced from Authelia SSO |
|
||||
| `workers` | Worker node registry with connection metadata |
|
||||
| `workflows` | Workflow definitions stored as JSON |
|
||||
| `executions` | Execution history with logs, status, and timestamps |
|
||||
|
||||
### `executions` Table Key Columns
|
||||
|
||||
| Column | Description |
|
||||
|--------|-------------|
|
||||
| `id` | Auto-increment primary key |
|
||||
| `worker_id` | Foreign key to workers |
|
||||
| `command` | The command that was executed |
|
||||
| `status` | `running`, `completed`, `failed` |
|
||||
| `output` | Command output / log (JSON or text) |
|
||||
| `created_at` | Execution start timestamp |
|
||||
| `completed_at` | Execution end timestamp |
|
||||
|
||||
### `workers` Table Key Columns
|
||||
|
||||
| Column | Description |
|
||||
|--------|-------------|
|
||||
| `id` | Auto-increment primary key |
|
||||
| `name` | Worker name (from `WORKER_NAME` env) |
|
||||
| `last_seen` | Last heartbeat timestamp |
|
||||
| `status` | `online`, `offline` |
|
||||
| `metadata` | JSON blob of system info |
|
||||
| Table | Key columns |
|
||||
|---|---|
|
||||
| `users` | `username`, `display_name`, `email`, `groups`, `last_login`: Authelia identities seen by Pulse |
|
||||
| `workers` | `id`, `name`, `status` (`online`/`offline`), `last_heartbeat`, `metadata` (JSON: system info, memory, load, version) |
|
||||
| `workflows` | `id`, `name`, `description`, `definition` (JSON), `webhook_url`, `created_by` |
|
||||
| `executions` | `id`, `workflow_id` (null for commands), `status` (`running`/`completed`/`failed`), `started_by` (a user, `gandalf:...` or `scheduler:<name>`), `started_at`, `completed_at`, `logs` (JSON list of steps, commands and results) |
|
||||
| `scheduled_commands` | `id`, `name`, `command`, `worker_ids` (JSON), `schedule_type`, `schedule_value`, `enabled`, `last_run`, `next_run` |
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
@@ -537,42 +542,14 @@ grep WORKER_API_KEY /opt/pulse-worker/.env
|
||||
```
|
||||
|
||||
### Commands Stuck in "Running"
|
||||
- This was fixed in recent updates - restart the server:
|
||||
```bash
|
||||
systemctl restart pulse.service
|
||||
```
|
||||
They shouldn't stay that way: a command fails when its worker disconnects, when no result
|
||||
arrives within its timeout, and a sweep every 5 minutes fails anything still running past
|
||||
`EXECUTION_MAX_MINUTES` (or left over from a server restart). If one does stay stuck, check
|
||||
`journalctl -u pulse` for the execution id.
|
||||
|
||||
### Clear All Executions
|
||||
Use the database directly if needed:
|
||||
```bash
|
||||
mysql -h 10.10.10.50 -u pulse_user -p pulse
|
||||
> DELETE FROM executions WHERE status IN ('completed', 'failed');
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
### Recent Updates
|
||||
|
||||
**Phase 1-6 Improvements:**
|
||||
- Formatted log display with color-coding
|
||||
- Worker system metrics monitoring
|
||||
- Command templates and history
|
||||
- Re-run and download execution features
|
||||
- Auto-cleanup and pagination
|
||||
- Terminal aesthetic refinements
|
||||
- Audio notifications and visual toasts
|
||||
|
||||
See git history for detailed changelog.
|
||||
|
||||
### Future Enhancements
|
||||
- Full workflow system implementation
|
||||
- Multi-worker command execution
|
||||
- Scheduled/cron job support
|
||||
- Execution search and filtering
|
||||
- Dark/light theme toggle
|
||||
- Mobile-responsive design
|
||||
- REST API documentation
|
||||
- Webhook integrations
|
||||
### Clear Completed Executions
|
||||
Use **Clear Completed** on the Executions tab; old executions are also deleted after
|
||||
`EXECUTION_RETENTION_DAYS`.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"license": "MIT",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"axios": "^1.20.0",
|
||||
|
||||
@@ -206,6 +206,12 @@ describe('availableMemory (#30)', () => {
|
||||
expect(availableMemory(meminfo)).toBe(459733 * 1024);
|
||||
});
|
||||
test('falls back to os.freemem() without a MemAvailable line', () => {
|
||||
expect(availableMemory('MemTotal: 1 kB\n')).toBe(require('os').freemem());
|
||||
// Stubbed: free memory changes between two real calls, which made this flaky.
|
||||
const spy = jest.spyOn(require('os'), 'freemem').mockReturnValue(123456);
|
||||
try {
|
||||
expect(availableMemory('MemTotal: 1 kB\n')).toBe(123456);
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
# PULSE worker configuration. Copy to /opt/pulse-worker/.env (chmod 600) and fill in.
|
||||
|
||||
WORKER_NAME=
|
||||
PULSE_SERVER=http://10.10.10.65:8080
|
||||
PULSE_WS=ws://10.10.10.65:8080
|
||||
HEARTBEAT_INTERVAL=30
|
||||
MAX_CONCURRENT_TASKS=5
|
||||
|
||||
# Same value as the server's WORKER_API_KEY.
|
||||
WORKER_API_KEY=
|
||||
Reference in new issue
Block a user