Architecture
System Overview
The SSI Agent operates as a systemd-native monitoring daemon on Linux systems. It consists of three main components:
- CLI Tool (
ssi) — For user interaction and configuration - Daemon (
ssi-agent-daemon) — Long-running process for backend communication - Service Scripts — BASH scripts managed by systemd
Rendering diagram...
Execution Model
Daemon Mode
The SSI Agent daemon (ssi-agent-daemon) is a long-running systemd service that:
- Maintains a WebSocket connection to the backend
- Watches log files for changes using file system events
- Parses log entries and sends status updates
- Handles connection failures with exponential backoff
The daemon is managed by systemd:
bash
1# Service file: /etc/systemd/system/ssi-agent.service
2systemctl status ssi-agent
3systemctl restart ssi-agent
4journalctl -u ssi-agent -fTimer-Based Execution
Service scripts are not executed by the daemon directly. Instead:
- Each service script has a corresponding systemd timer
- The timer triggers a systemd service unit
- The service unit executes the BASH script
- Script output is captured to log files
- The daemon watches log files and reports changes
This design ensures:
- Reliability: systemd handles scheduling, timeouts, and restarts
- Isolation: Each script runs in its own process
- Transparency: Standard systemd tools work (
journalctl,systemctl)
Unit File Structure
For a service with ID api_health, the following files are created:
/etc/systemd/system/
├── ssi-api-health.service # Executes the script
└── ssi-api-health.timer # Schedules execution
Service Unit (ssi-api-health.service):
ini
1[Unit]
2Description=Checks the health of an API
3After=network.target
4
5[Service]
6Type=oneshot
7ExecStart=/bin/bash -c '/opt/ssi-agent/.installed-service-scripts/api-health.bash'
8TimeoutSec=10
9StandardOutput=append:/var/log/ssi-agent/api-health.log
10StandardError=append:/var/log/ssi-agent/api-health.logTimer Unit (ssi-api-health.timer):
ini
1[Unit]
2Description=Timer for API health check
3
4[Timer]
5OnCalendar=*:0/01:00
6Persistent=true
7RandomizedDelaySec=30
8
9[Install]
10WantedBy=timers.targetDirectory Structure
Rendering diagram...
Communication Flow
Status Reporting
Rendering diagram...
-
Script executes and prints to stdout:
2024-01-15 10:30:00, OK, API is healthy -
systemd captures output to log file:
/var/log/ssi-agent/api-health.log -
Daemon detects file change and parses the new line
-
Daemon sends status update via WebSocket:
json1{ 2 "service_id": "api-health", 3 "status": "OK", 4 "message": "API is healthy", 5 "timestamp": "2024-01-15T10:30:00" 6} -
Backend receives and broadcasts to connected clients
Registration Flow
Rendering diagram...
ssi registerrequests a registration code from the backend- Backend generates a 6-digit code and UUID pair
- User enters the code in the mobile app
- Mobile app confirms registration with backend
- CLI polls for confirmation and receives agent key
- Agent key is stored in
/etc/ssi-agent/config.json
Resource Constraints
| Resource | Expectation |
|---|---|
| CPU | Minimal baseline, burst-only during checks |
| Memory | < 50MB typical usage |
| Disk I/O | Read-only except logs and config |
| Network | Single WebSocket connection |
Failure Handling
Fail-Fast (Fatal Errors)
The agent exits immediately on:
- Invalid or missing configuration
- Invalid authentication credentials
- Missing systemd dependency
- Corrupt persistent state
Fail-Soft (Recoverable)
The agent retries with backoff on:
- Transient network failures
- Backend temporarily unavailable
- Individual script failures
Security Model
Agent Permissions
- Runs as dedicated
ssi-agentuser - Read access to service scripts
- Write access to log directory
- Read/Write access to config directory
Authentication
- Agent authenticates with a unique agent key
- Key is obtained during registration
- Key is stored securely in config file
- All communication uses TLS (WSS/HTTPS)
Trust Model
- Agent is semi-trusted (limited permissions)
- Agent cannot modify backend configuration
- Agent cannot execute arbitrary remote commands
- Agent can only report status