Files
dropshell-templates/logclient/install.sh
Your Name fa4ef61a0a
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 40s
Update 4 files
2025-09-20 10:26:23 +12:00

64 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
source "${AGENT_PATH}/common.sh"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Check required environment variables
_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "LOGSERVER_HOST" "LOGSERVER_PORT" "API_KEY"
# Validate API key
if [ -z "$API_KEY" ]; then
echo ""
echo "ERROR: API_KEY is not configured"
echo ""
echo "To get an API key:"
echo "1. On the logserver, run: ./generate-api-key.sh"
echo "2. Enter this client's hostname when prompted"
echo "3. Copy the generated API_KEY to this client's service.env"
echo ""
_die "Missing API_KEY configuration"
fi
# Check Docker is available
_check_docker_installed || _die "Docker test failed"
# Test connectivity to logserver
echo "Testing connectivity to logserver at ${LOGSERVER_HOST}:${LOGSERVER_PORT}..."
nc -zv "$LOGSERVER_HOST" "$LOGSERVER_PORT" 2>/dev/null || echo "WARNING: Cannot connect to logserver. Will retry when container starts."
# Pull the Docker image
docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull Filebeat image"
# Stop any existing container
bash ./stop.sh || true
# Remove old container
_remove_container "$CONTAINER_NAME" || true
# Generate Filebeat configuration
echo "Generating Filebeat configuration..."
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bash "$SCRIPT_DIR/scripts/generate-config.sh" || _die "Failed to generate configuration"
# Create Docker volumes
CONFIG_VOLUME="${CONFIG_VOLUME:-${CONTAINER_NAME}_config}"
DATA_VOLUME="${DATA_VOLUME:-${CONTAINER_NAME}_data}"
CERTS_VOLUME="${CERTS_VOLUME:-${CONTAINER_NAME}_certs}"
echo "Creating Docker volumes..."
docker volume create "$CONFIG_VOLUME" >/dev/null 2>&1 || true
docker volume create "$DATA_VOLUME" >/dev/null 2>&1 || true
docker volume create "$CERTS_VOLUME" >/dev/null 2>&1 || true
# Copy config to volume
if [ -f "${CONFIG_PATH}/filebeat.yml" ]; then
echo "Copying configuration to Docker volume..."
docker run --rm -v "${CONFIG_VOLUME}:/config" -v "${CONFIG_PATH}:/source:ro" alpine \
cp /source/filebeat.yml /config/filebeat.yml
fi
# Start the new container
bash ./start.sh || _die "Failed to start Filebeat"
echo "Installation of ${CONTAINER_NAME} complete"
echo "Collecting logs from Docker API and shipping to ${LOGSERVER_HOST}:${LOGSERVER_PORT}"
echo "Using API key authentication"