This commit is contained in:
pika 2025-03-24 18:30:47 +01:00
parent 105c18ba14
commit 72ddf7a3ee
3 changed files with 29 additions and 3 deletions

View file

@ -10,3 +10,4 @@ DASHBOARD_URL=https://dashboard.example.com/api/update
# only if you want to change the internal path of the Caddyfile # only if you want to change the internal path of the Caddyfile
# SERVER_NAME=my-caddy-server # Optional - defaults to hostname # SERVER_NAME=my-caddy-server # Optional - defaults to hostname
CHECK_INTERVAL=60 # Seconds between checks CHECK_INTERVAL=60 # Seconds between checks
VERIFY_SSL=true # Set to false to disable SSL certificate verification (insecure but useful for testing)

View file

@ -13,16 +13,18 @@ from datetime import datetime, timedelta
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
from dotenv import load_dotenv from dotenv import load_dotenv
import urllib3
# Load environment variables # Load environment variables
load_dotenv() load_dotenv()
# Fixed configuration # Fixed configuration
CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path CADDYFILE_PATH = "/app/Caddyfile" # Fixed internal path
DASHBOARD_URL = os.getenv('DASHBOARD_URL') DASHBOARD_URL = os.getenv('DASHBOARD_URL', 'http://caddydb-server:5000/api/update')
SERVER_NAME = os.getenv('SERVER_NAME', socket.gethostname()) SERVER_NAME = os.getenv('SERVER_NAME', socket.gethostname())
API_KEY = os.getenv('API_KEY') API_KEY = os.getenv('API_KEY')
CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', '60')) CHECK_INTERVAL = int(os.getenv('CHECK_INTERVAL', '60'))
VERIFY_SSL = os.getenv('VERIFY_SSL', 'true').lower() == 'true'
# Setup logging # Setup logging
logging.basicConfig( logging.basicConfig(
@ -31,6 +33,19 @@ logging.basicConfig(
) )
logger = logging.getLogger('caddy-agent') logger = logging.getLogger('caddy-agent')
# Debug configuration
logger.info(f"Starting Caddy agent with configuration:")
logger.info(f"- DASHBOARD_URL: {DASHBOARD_URL}")
logger.info(f"- SERVER_NAME: {SERVER_NAME}")
logger.info(f"- CADDYFILE_PATH: {CADDYFILE_PATH}")
logger.info(f"- VERIFY_SSL: {VERIFY_SSL}")
logger.info(f"- API_KEY set: {'Yes' if API_KEY else 'No'}")
# Disable SSL warnings if verification is disabled
if not VERIFY_SSL:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
logger.warning("SSL verification is disabled - this is insecure!")
# Validate required configuration # Validate required configuration
if not os.path.exists(CADDYFILE_PATH): if not os.path.exists(CADDYFILE_PATH):
logger.error(f"Caddyfile not found at {CADDYFILE_PATH}") logger.error(f"Caddyfile not found at {CADDYFILE_PATH}")
@ -128,7 +143,8 @@ def send_update(force=False):
DASHBOARD_URL, DASHBOARD_URL,
json=data, json=data,
headers=headers, headers=headers,
timeout=10 # Set a reasonable timeout timeout=10, # Set a reasonable timeout
verify=VERIFY_SSL # Control SSL verification
) )
if response.status_code == 200: if response.status_code == 200:

View file

@ -11,6 +11,8 @@ services:
- ./Caddyfile:/app/Caddyfile:ro - ./Caddyfile:/app/Caddyfile:ro
command: server command: server
restart: unless-stopped restart: unless-stopped
networks:
- caddy-network
# Agent mode (example) # Agent mode (example)
caddydb-agent: caddydb-agent:
@ -22,5 +24,12 @@ services:
- DASHBOARD_URL=http://caddydb-server:5000/api/update - DASHBOARD_URL=http://caddydb-server:5000/api/update
- SERVER_NAME=caddy-server-1 - SERVER_NAME=caddy-server-1
- CHECK_INTERVAL=60 - CHECK_INTERVAL=60
- VERIFY_SSL=false # Set to false if using self-signed certificates
command: agent command: agent
restart: unless-stopped restart: unless-stopped
networks:
- caddy-network
networks:
caddy-network:
driver: bridge