#!/bin/bash
# deploy-es.sh

set -e

# 加载环境变量
source .env

# 创建目录
mkdir -p ./data/elasticsearch/{data,logs,snapshots}

# 生成 elasticsearch.yml 配置文件
cat > ./configs/elasticsearch/elasticsearch.yml << EOF
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
node.name: stec-platform-prod-prod-es
network.host: 0.0.0.0
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
path.repo: ["/usr/share/elasticsearch/snapshots"]
EOF
cat > ./configs/elasticsearch/hosts << EOF
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.18.0.2	6fdec2fa9ed7
152.32.137.93 geoip.elastic.co
EOF

# 设置权限
chown -R 1000:1000 ./data/elasticsearch

# 启动服务
docker compose up -d

echo "Elasticsearch 启动完成！"
