health
The health command runs diagnostic checks to verify that NextDNS Blocker is properly configured and can communicate with the NextDNS API.
nextdns-blocker health [OPTIONS]Options
Section titled “Options”| Option | Description |
|---|---|
--config-dir | Config directory (default: auto-detect) |
--help | Show help message |
What It Checks
Section titled “What It Checks”The health command performs four critical checks:
1. Configuration Loading
Section titled “1. Configuration Loading”Verifies that:
.envfile exists and is readable- Required environment variables are set (
NEXTDNS_API_KEY,NEXTDNS_PROFILE_ID) - Configuration values are valid
2. Domains Loading
Section titled “2. Domains Loading”Verifies that:
config.jsonfile exists and is valid JSON- Domain entries are properly formatted
- Schedules are syntactically correct
3. API Connectivity
Section titled “3. API Connectivity”Verifies that:
- API key is valid
- Profile ID exists
- NextDNS API is reachable
- Current denylist can be fetched
4. Log Directory
Section titled “4. Log Directory”Verifies that:
- Log directory exists or can be created
- Directory is writable
- Audit log can be accessed
Examples
Section titled “Examples”Basic Health Check
Section titled “Basic Health Check”nextdns-blocker healthOutput (healthy system):
Health Check ------------ [✓] Configuration loaded [✓] Domains loaded (5 domains, 2 allowlist) [✓] API connectivity (12 items in denylist) [✓] Log directory: /Users/you/.local/share/nextdns-blocker/logs
Result: 4/4 checks passed Status: HEALTHYFailing Health Check
Section titled “Failing Health Check”nextdns-blocker healthOutput (issues detected):
Health Check ------------ [✓] Configuration loaded [✓] Domains loaded (5 domains, 2 allowlist) [✗] API connectivity failed
Result: 2/4 checks passed Status: DEGRADEDCustom Config Directory
Section titled “Custom Config Directory”nextdns-blocker health --config-dir /path/to/configExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | All checks passed (HEALTHY) |
| 1 | One or more checks failed (DEGRADED) |
When to Use
Section titled “When to Use”Run health when:
- After installation - Verify setup is correct
- After configuration changes - Ensure changes are valid
- When sync fails - Diagnose connection issues
- Before troubleshooting - Quick system status overview
- In automation - Verify system is operational
Troubleshooting
Section titled “Troubleshooting”Configuration failed
Section titled “Configuration failed”[✗] Configuration: Missing required environment variable: NEXTDNS_API_KEYSolution: Run nextdns-blocker init to set up configuration.
Domains failed
Section titled “Domains failed”[✗] Domains: Invalid JSON in config.jsonSolution:
- Validate your config:
nextdns-blocker config validate - Fix syntax errors in
config.json
API connectivity failed
Section titled “API connectivity failed”[✗] API connectivity failedSolutions:
- Check internet connection
- Verify API key is correct
- Verify profile ID exists
- Check NextDNS service status
Log directory failed
Section titled “Log directory failed”[✗] Log directory: Permission deniedSolution: Check permissions on the data directory or run with appropriate user.
Integration with Other Commands
Section titled “Integration with Other Commands”Use health as part of a diagnostic workflow:
# Quick system checknextdns-blocker health
# If healthy, run syncnextdns-blocker config push
# If degraded, run fixnextdns-blocker fixScripting
Section titled “Scripting”Use in scripts to verify system before operations:
#!/bin/bashif nextdns-blocker health > /dev/null 2>&1; then echo "System healthy, proceeding..." nextdns-blocker config pushelse echo "System degraded, please check configuration" exit 1fi