DefenraAgent includes a built-in self-update mechanism that allows you to easily upgrade to the latest version from GitHub releases.
Check if a newer version is available without installing it:
defenra-agent check-updateExample output:
🔍 Checking for updates...
Current version: v1.0.0
✨ New version available: v1.1.0
To update, run:
sudo defenra-agent update
Download and install the latest version:
sudo defenra-agent updateNote: Requires sudo on Linux/macOS because the agent binary is typically installed in a system directory.
Example output:
🔍 Checking for updates...
Current version: v1.0.0
📦 New version available: v1.0.0 → v1.1.0
⬇️ Downloading update...
🔐 Verifying checksum...
📂 Extracting update...
🔄 Installing update...
✅ Successfully updated to version v1.1.0
🔄 Please restart the agent for changes to take effect
Display current version information:
defenra-agent versionExample output:
Defenra Agent
Version: v1.0.0
Build Date: 2024-01-15T10:30:00Z
Git Commit: abc12345
Go Version: go1.21+
OS/Arch: linux/amd64
- Check GitHub Releases: The updater queries the GitHub API for the latest release
- Compare Versions: Compares the current version with the latest available version
- Download Binary: Downloads the platform-specific binary (e.g.,
defenra-agent-linux-amd64.tar.gz) - Verify Checksum: Verifies the SHA256 checksum to ensure integrity
- Extract Archive: Extracts the binary from the tar.gz archive
- Backup & Replace: Backs up the current binary and replaces it with the new one
- Set Permissions: Sets executable permissions on the new binary
Every release includes SHA256 checksums. The updater automatically verifies the downloaded file matches the expected checksum before installation.
All downloads are performed over HTTPS to prevent man-in-the-middle attacks.
The current binary is backed up before replacement. If the update fails, the backup is automatically restored.
The self-update feature works on all platforms where DefenraAgent is released:
- Linux (AMD64, ARM64)
- macOS (AMD64, ARM64/M1/M2)
- FreeBSD (AMD64, ARM64)
The updater automatically detects your platform and downloads the correct binary.
Development builds (version = "dev") cannot be updated via this mechanism. You must build from source or download a release manually.
$ defenra-agent check-update
🔍 Checking for updates...
Current version: dev
❌ Failed to check for updates: development version cannot be updated via this commandIf the agent is running as a systemd service, you need to restart the service after updating:
# Update the binary
sudo defenra-agent update
# Restart the service
sudo systemctl restart defenra-agentThe update command requires write permissions to the agent binary location. On Linux/macOS, this typically requires sudo.
Problem: Cannot write to the binary location.
Solution: Run with sudo:
sudo defenra-agent updateProblem: Downloaded file doesn't match expected checksum.
Solution: This could indicate a corrupted download or security issue. Try again:
sudo defenra-agent updateIf the problem persists, download manually from GitHub releases.
Problem: Cannot connect to GitHub API.
Solution:
- Check your internet connection
- Verify GitHub is accessible:
curl https://api.github.com - Check if you're behind a proxy or firewall
The updater creates a backup before replacing the binary. If the update fails, the backup is automatically restored, so your agent continues to work with the old version.
If the self-update feature doesn't work, you can always update manually:
- Download the latest release from GitHub Releases
- Verify the checksum:
sha256sum -c defenra-agent-linux-amd64.tar.gz.sha256
- Extract the archive:
tar -xzf defenra-agent-linux-amd64.tar.gz
- Replace the binary:
sudo mv defenra-agent-linux-amd64 /usr/local/bin/defenra-agent sudo chmod +x /usr/local/bin/defenra-agent
- Restart the agent:
sudo systemctl restart defenra-agent
You can automate update checks using cron:
# Check for updates daily at 3 AM
0 3 * * * /usr/local/bin/defenra-agent check-updateFor automatic updates (use with caution):
# Auto-update weekly on Sunday at 3 AM
0 3 * * 0 /usr/local/bin/defenra-agent update && systemctl restart defenra-agentWarning: Automatic updates can cause unexpected downtime. Always test updates in a staging environment first.
The GitHub API has rate limits:
- Unauthenticated: 60 requests per hour
- Authenticated: 5000 requests per hour
The updater uses unauthenticated requests, which is sufficient for normal usage. If you need higher limits, you can set a GitHub token (future feature).