
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 40s
62 lines
2.4 KiB
Bash
Executable File
62 lines
2.4 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" "ES_VERSION" "LS_VERSION" "KIBANA_VERSION"
|
|
|
|
# Check Docker and Docker Compose are available
|
|
_check_docker_installed || _die "Docker test failed"
|
|
which docker-compose >/dev/null 2>&1 || _die "docker-compose is not installed"
|
|
|
|
# Check vm.max_map_count for Elasticsearch
|
|
current_max_map_count=$(sysctl -n vm.max_map_count 2>/dev/null || echo 0)
|
|
if [ "$current_max_map_count" -lt 262144 ]; then
|
|
echo "WARNING: vm.max_map_count is too low ($current_max_map_count)"
|
|
echo "Elasticsearch requires at least 262144"
|
|
echo "Please run: sudo sysctl -w vm.max_map_count=262144"
|
|
echo "And add to /etc/sysctl.conf to persist"
|
|
_die "System configuration needs adjustment"
|
|
fi
|
|
|
|
# Stop any existing containers
|
|
bash ./stop.sh || true
|
|
|
|
# Remove old containers
|
|
docker-compose down --remove-orphans 2>/dev/null || true
|
|
|
|
# Pull the Docker images
|
|
echo "Pulling ELK stack images..."
|
|
docker pull docker.elastic.co/elasticsearch/elasticsearch:${ES_VERSION} || _die "Failed to pull Elasticsearch"
|
|
docker pull docker.elastic.co/logstash/logstash:${LS_VERSION} || _die "Failed to pull Logstash"
|
|
docker pull docker.elastic.co/kibana/kibana:${KIBANA_VERSION} || _die "Failed to pull Kibana"
|
|
|
|
# Generate certificates if using mTLS
|
|
if [ "$AUTH_MODE" = "mtls" ]; then
|
|
bash ./scripts/generate-ca.sh || _die "Failed to generate CA certificate"
|
|
bash ./scripts/generate-server-cert.sh || _die "Failed to generate server certificate"
|
|
fi
|
|
|
|
# Start the ELK stack
|
|
echo "Starting ELK stack..."
|
|
docker-compose up -d --build || _die "Failed to start ELK stack"
|
|
|
|
# Wait for services to be ready
|
|
echo "Waiting for services to start..."
|
|
sleep 10
|
|
|
|
# Check status
|
|
bash ./status.sh || _die "Services failed to start properly"
|
|
|
|
echo "Installation of ${CONTAINER_NAME} complete"
|
|
echo ""
|
|
echo "Kibana UI: http://$(hostname -I | awk '{print $1}'):${KIBANA_PORT}"
|
|
echo "Username: elastic"
|
|
echo "Password: ${KIBANA_PASSWORD}"
|
|
echo ""
|
|
echo "Logstash listening on port ${LOGSTASH_BEATS_PORT} for Filebeat clients"
|
|
if [ "$AUTH_MODE" = "mtls" ]; then
|
|
echo "Authentication: mTLS (generate client certs with ./scripts/generate-client-cert.sh)"
|
|
elif [ "$AUTH_MODE" = "apikey" ]; then
|
|
echo "Authentication: API Keys (generate with ./scripts/generate-api-key.sh)"
|
|
fi |