Files
dropshell-templates/logserver/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

78 lines
2.6 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"
# Check Docker
_check_docker_installed || _die "Docker test failed"
docker compose version >/dev/null 2>&1 || _die "Docker Compose V2 is required"
# Stop any existing containers
bash ./stop.sh 2>/dev/null || true
# Create config directory
mkdir -p "${CONFIG_PATH}/dashboards"
# Copy configuration files
cp "$SCRIPT_DIR/config/"*.yaml "$SCRIPT_DIR/config/"*.yml "$SCRIPT_DIR/config/"*.conf "${CONFIG_PATH}/" 2>/dev/null || true
cp "$SCRIPT_DIR/config/dashboards/"*.json "${CONFIG_PATH}/dashboards/" 2>/dev/null || true
# Generate htpasswd file for Loki authentication
echo "Generating authentication file..."
# Use openssl to generate htpasswd (available on most systems)
if command -v openssl >/dev/null 2>&1; then
# Generate password hash
PASS_HASH=$(openssl passwd -apr1 "${LOKI_PASSWORD:-changeme}")
echo "${LOKI_USER:-logclient}:$PASS_HASH" > "${CONFIG_PATH}/.htpasswd"
elif command -v htpasswd >/dev/null 2>&1; then
# Use htpasswd if available
htpasswd -cb "${CONFIG_PATH}/.htpasswd" "${LOKI_USER:-logclient}" "${LOKI_PASSWORD:-changeme}"
else
echo "WARNING: Cannot generate password file - no openssl or htpasswd found"
echo "Using basic auth with plain text (NOT SECURE):"
echo "${LOKI_USER:-logclient}:${LOKI_PASSWORD:-changeme}" > "${CONFIG_PATH}/.htpasswd"
fi
# Start the stack
echo "Starting Log Server..."
docker compose up -d || _die "Failed to start"
# Wait for services
echo -n "Waiting for services to start..."
MAX_WAIT=60
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
if curl -s "http://localhost:${WEB_PORT:-3000}/api/health" 2>/dev/null | grep -q "ok"; then
echo " Ready!"
break
fi
echo -n "."
sleep 2
WAITED=$((WAITED + 2))
done
echo ""
echo ""
echo "========================================="
echo "Log Server Installed!"
echo "========================================="
echo ""
echo "Web UI: http://$(hostname -I | awk '{print $1}'):${WEB_PORT:-3000}"
echo "Login: ${ADMIN_USER:-admin} / ${ADMIN_PASSWORD:-changeme}"
echo ""
echo "TO VIEW LOGS:"
echo "1. Click 'Dashboards' (4 squares icon)"
echo "2. Click 'Central Logs'"
echo "3. See all logs from all servers!"
echo ""
echo "FOR CLIENTS TO SEND LOGS HERE:"
echo "Server: $(hostname -I | awk '{print $1}')"
echo "Port: ${LOKI_PORT:-3100}"
echo "Username: ${LOKI_USER:-logclient}"
echo "Password: ${LOKI_PASSWORD:-changeme}"
echo ""
echo "IMPORTANT: Change LOKI_PASSWORD in service.env!"
echo ""
echo "Install 'logclient' on other servers"
echo "========================================="