-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsetup-ccr
More file actions
executable file
·89 lines (77 loc) · 2.2 KB
/
Copy pathsetup-ccr
File metadata and controls
executable file
·89 lines (77 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Function to display help
show_help() {
echo "Usage: $0 [option] [license]"
echo "Options:"
echo " up - Start the clusters and apply the license"
echo " down - Shut down the clusters"
echo " help - Display this help message"
}
# Function to apply the license to a cluster
apply_license() {
local port=$1
local license="$2"
local response_file=$(mktemp)
local http_code
http_code=$(curl -s -o "$response_file" -w "%{http_code}" -X PUT "http://localhost:$port/_license?pretty" -H "Content-Type: application/json" -d "$license")
if [ "$http_code" -ne 200 ]; then
echo "Failed to apply license to cluster on port $port. HTTP status code: $http_code"
echo "Error response: $(cat "$response_file")"
rm "$response_file"
exit 1
fi
}
# Function to shut down the clusters
shutdown_clusters() {
docker compose --project-directory docker --profile ccr down
echo "Clusters shut down."
}
# Check for options
case "$1" in
up)
# Get the directory of the current script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Start the clusters
docker compose --project-directory docker --profile ccr up -d
# Wait for both clusters to be online
export ES_PORT=9208
"$SCRIPT_DIR/poll-for-es"
export ES_PORT=9209
"$SCRIPT_DIR/poll-for-es"
# Apply the license to both clusters
LICENSE=$2
if [ -z "$LICENSE" ]; then
echo "License key is required as the second argument."
exit 1
fi
echo "Applying license to cluster on port 9208..."
apply_license 9208 "$LICENSE"
echo "Applying license to cluster on port 9209..."
apply_license 9209 "$LICENSE"
echo "License applied to both clusters."
# Set up the remote connection between the clusters
curl -X PUT "http://localhost:9209/_cluster/settings" -H "Content-Type: application/json" -d '{
"persistent": {
"cluster": {
"remote": {
"leader": {
"seeds": ["es8.18:9300"]
}
}
}
}
}'
echo "Clusters setup completed."
;;
down)
shutdown_clusters
;;
help)
show_help
;;
*)
echo "Invalid option: $1"
show_help
exit 1
;;
esac