wip
This commit is contained in:
parent
eac9d2f510
commit
105c18ba14
4 changed files with 17 additions and 22 deletions
|
@ -3,11 +3,10 @@ API_KEY=your_secure_random_key_here
|
|||
|
||||
# Server mode configurations
|
||||
DEBUG_MODE=false
|
||||
CADDYFILE_PATH=/path/to/local/Caddyfile # Only needed in LOCAL_MODE
|
||||
|
||||
# Agent mode configurations
|
||||
CADDYFILE_PATH=/opt/docker/caddy/conf/Caddyfile
|
||||
DASHBOARD_URL=https://dashboard.example.com/api/update
|
||||
# or DASHBOARD_URL=http://caddydb-server:5000/api/update
|
||||
|
||||
# Agent mode configurations
|
||||
# only if you want to change the internal path of the Caddyfile
|
||||
# SERVER_NAME=my-caddy-server # Optional - defaults to hostname
|
||||
CHECK_INTERVAL=60 # Seconds between checks
|
16
agent.py
16
agent.py
|
@ -8,21 +8,21 @@ import requests
|
|||
import socket
|
||||
import re
|
||||
import logging
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
from watchdog.observers import Observer
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Configuration
|
||||
CADDYFILE_PATH = os.getenv('CADDYFILE_PATH')
|
||||
# Fixed configuration
|
||||
CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path
|
||||
DASHBOARD_URL = os.getenv('DASHBOARD_URL')
|
||||
SERVER_NAME = os.getenv('SERVER_NAME', socket.gethostname()) # Hostname is a reasonable default
|
||||
API_KEY = os.getenv('API_KEY')
|
||||
CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', '60')) # Default check interval is reasonable
|
||||
SERVER_NAME = os.getenv('SERVER_NAME', socket.gethostname())
|
||||
API_KEY = os.getenv('API_KEY')
|
||||
CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', '60'))
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(
|
||||
|
@ -32,10 +32,6 @@ logging.basicConfig(
|
|||
logger = logging.getLogger('caddy-agent')
|
||||
|
||||
# Validate required configuration
|
||||
if not CADDYFILE_PATH:
|
||||
logger.error("CADDYFILE_PATH environment variable not set - cannot monitor Caddyfile")
|
||||
sys.exit(1)
|
||||
|
||||
if not os.path.exists(CADDYFILE_PATH):
|
||||
logger.error(f"Caddyfile not found at {CADDYFILE_PATH}")
|
||||
sys.exit(1)
|
||||
|
|
10
app.py
10
app.py
|
@ -11,10 +11,10 @@ from dotenv import load_dotenv
|
|||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
# Configuration
|
||||
# Configuration with fixed Caddyfile path
|
||||
API_KEY = os.getenv('API_KEY')
|
||||
DEBUG_MODE = os.getenv('DEBUG_MODE', 'false').lower() == 'true'
|
||||
CADDYFILE_PATH = os.getenv('CADDYFILE_PATH') # No default - if not set, we don't use local file
|
||||
CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(
|
||||
|
@ -24,10 +24,10 @@ logging.basicConfig(
|
|||
logger = logging.getLogger('caddy-dashboard')
|
||||
|
||||
# Determine if we should use local Caddyfile reading
|
||||
USE_LOCAL_CADDYFILE = CADDYFILE_PATH and os.path.exists(CADDYFILE_PATH)
|
||||
USE_LOCAL_CADDYFILE = os.path.exists(CADDYFILE_PATH)
|
||||
|
||||
if CADDYFILE_PATH and not USE_LOCAL_CADDYFILE:
|
||||
logger.warning(f"CADDYFILE_PATH is set but file not found at: {CADDYFILE_PATH}")
|
||||
if not USE_LOCAL_CADDYFILE:
|
||||
logger.warning(f"Caddyfile not found at the standard path: {CADDYFILE_PATH}")
|
||||
|
||||
if not API_KEY:
|
||||
logger.warning("API_KEY not set - running without authentication! This is insecure.")
|
||||
|
|
|
@ -8,7 +8,7 @@ services:
|
|||
- API_KEY=${API_KEY}
|
||||
- DEBUG_MODE=false
|
||||
volumes:
|
||||
- ./.env:/app/.env:ro # Mount .env file
|
||||
- ./Caddyfile:/app/Caddyfile:ro
|
||||
command: server
|
||||
restart: unless-stopped
|
||||
|
||||
|
@ -16,11 +16,11 @@ services:
|
|||
caddydb-agent:
|
||||
image: caddydb:latest
|
||||
volumes:
|
||||
- /opt/docker/caddy/conf/Caddyfile:/opt/docker/caddy/conf/Caddyfile:ro
|
||||
- ./.env:/app/.env:ro # Mount .env file
|
||||
- /path/to/host/Caddyfile:/app/Caddyfile:ro
|
||||
environment:
|
||||
- API_KEY=${API_KEY}
|
||||
- DASHBOARD_URL=http://caddydb-server:5000/api/update
|
||||
- SERVER_NAME=caddy-server-1
|
||||
- CHECK_INTERVAL=60
|
||||
command: agent
|
||||
restart: unless-stopped
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue