test
This commit is contained in:
66
opensearch-master/rootfs/usr/bin/configure-opensearch
Normal file
66
opensearch-master/rootfs/usr/bin/configure-opensearch
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Function to read configuration using bashio if available
|
||||
read_config() {
|
||||
if command -v bashio >/dev/null 2>&1; then
|
||||
bashio::config "$1"
|
||||
else
|
||||
# Fallback for testing outside Home Assistant
|
||||
echo "Testing mode - using default values"
|
||||
case "$1" in
|
||||
"node_role") echo "master" ;;
|
||||
"cluster_name") echo "hass-opensearch-cluster" ;;
|
||||
"node_name") echo "os-node-1" ;;
|
||||
"heap_size") echo "1g" ;;
|
||||
"http_port") echo "9200" ;;
|
||||
"transport_port") echo "9300" ;;
|
||||
"discovery_seed_hosts") echo '["os-master:9300", "os-data-1:9300"]' ;;
|
||||
"initial_master_nodes") echo '["os-master"]' ;;
|
||||
"security_enabled") echo "true" ;;
|
||||
"admin_password") echo "SecurePass123!" ;;
|
||||
"plugins") echo "[]" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
# Read configuration values
|
||||
NODE_ROLE=$(read_config 'node_role' | tr -d '[]"' | tr ',' ' ')
|
||||
CLUSTER_NAME=$(read_config 'cluster_name')
|
||||
NODE_NAME=$(read_config 'node_name')
|
||||
HEAP_SIZE=$(read_config 'heap_size')
|
||||
HTTP_PORT=$(read_config 'http_port')
|
||||
TRANSPORT_PORT=$(read_config 'transport_port')
|
||||
DISCOVERY_SEEDS=$(read_config 'discovery_seed_hosts' | tr -d '[]" ' | tr ',' ' ')
|
||||
INITIAL_MASTERS=$(read_config 'initial_master_nodes' | tr -d '[]" ' | tr ',' ' ')
|
||||
SECURITY_ENABLED=$(read_config 'security_enabled')
|
||||
ADMIN_PASSWORD=$(read_config 'admin_password')
|
||||
|
||||
# Export environment variables
|
||||
export OPENSEARCH_INITIAL_ADMIN_PASSWORD="${ADMIN_PASSWORD}"
|
||||
export DISCOVERY_TYPE="multi-node"
|
||||
|
||||
# Set heap size
|
||||
echo "-Xms${HEAP_SIZE}" > /usr/share/opensearch/config/jvm.options.d/heap.options
|
||||
echo "-Xmx${HEAP_SIZE}" >> /usr/share/opensearch/config/jvm.options.d/heap.options
|
||||
|
||||
# Export variables for envsubst
|
||||
export CLUSTER_NAME NODE_NAME NODE_ROLE HTTP_PORT TRANSPORT_PORT
|
||||
export DISCOVERY_SEEDS INITIAL_MASTERS SECURITY_ENABLED
|
||||
|
||||
# Generate opensearch.yml from template
|
||||
envsubst < /etc/opensearch/opensearch.yml.template > /usr/share/opensearch/config/opensearch.yml
|
||||
|
||||
# Install plugins if specified
|
||||
PLUGINS_JSON=$(read_config 'plugins')
|
||||
if [ -n "$PLUGINS_JSON" ] && [ "$PLUGINS_JSON" != "[]" ]; then
|
||||
# Extract plugins from JSON array
|
||||
PLUGINS=$(echo "$PLUGINS_JSON" | tr -d '[]"' | tr ',' '\n' | sed 's/^ *//;s/ *$//')
|
||||
for plugin in $PLUGINS; do
|
||||
echo "Installing plugin: $plugin"
|
||||
/usr/share/opensearch/bin/opensearch-plugin install --batch "$plugin" || true
|
||||
done
|
||||
fi
|
||||
|
||||
# Start OpenSearch (use exec to replace the current process)
|
||||
exec /usr/share/opensearch/bin/opensearch
|
Reference in New Issue
Block a user