Files
dropshell-templates/logclient/install.sh
Your Name f114773d78
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 40s
swtich from ELK to Loki!
2025-09-20 12:01:25 +12:00

40 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
source "${AGENT_PATH}/common.sh"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
_check_required_env_vars "CONTAINER_NAME" "LOGSERVER_HOST" "LOGSERVER_PORT" "LOKI_PASSWORD"
# Check Docker
_check_docker_installed || _die "Docker test failed"
# Test connectivity to logserver
echo "Testing connectivity to log server at ${LOGSERVER_HOST}:${LOGSERVER_PORT}..."
nc -zv "$LOGSERVER_HOST" "$LOGSERVER_PORT" 2>/dev/null || echo "WARNING: Cannot connect to log server. Will retry when container starts."
# Stop any existing container
bash ./stop.sh 2>/dev/null || true
# Generate configuration
echo "Generating configuration..."
export HOSTNAME=$(hostname)
bash "$SCRIPT_DIR/scripts/generate-config.sh" || _die "Failed to generate configuration"
# Start the client
echo "Starting Log Client..."
docker compose up -d || _die "Failed to start"
echo ""
echo "========================================="
echo "Log Client Installed!"
echo "========================================="
echo ""
echo "Shipping logs to: ${LOGSERVER_HOST}:${LOGSERVER_PORT}"
echo "Using authentication: ${LOKI_USER:-logclient}"
echo "Hostname label: $(hostname)"
echo ""
echo "Collecting:"
echo " - All Docker container logs"
echo " - System logs (/var/log)"
echo ""
echo "View logs at: http://${LOGSERVER_HOST}:3000"
echo "========================================="