
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 38s
52 lines
1.8 KiB
Bash
Executable File
52 lines
1.8 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 volumes using common function
|
|
source "$SCRIPT_DIR/_volumes.sh"
|
|
echo "Creating volumes..."
|
|
create_items $(get_logclient_volumes)
|
|
|
|
# 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" |