-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathcreate-namespace.sh
More file actions
executable file
·65 lines (53 loc) · 1.89 KB
/
create-namespace.sh
File metadata and controls
executable file
·65 lines (53 loc) · 1.89 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
#!/bin/sh
set -eu
NAMESPACE=${DEFAULT_NAMESPACE:-default}
TEMPORAL_ADDRESS=${TEMPORAL_ADDRESS:-temporal:7233}
MAX_ATTEMPTS=${TEMPORAL_HEALTH_CHECK_MAX_ATTEMPTS:-30}
SLEEP_SECONDS=${TEMPORAL_HEALTH_CHECK_SLEEP_SECONDS:-5}
echo "Waiting for Temporal server port to be available..."
SERVER_HOST=$(echo "$TEMPORAL_ADDRESS" | cut -d: -f1)
SERVER_PORT=$(echo "$TEMPORAL_ADDRESS" | cut -d: -f2)
attempt=1
while ! nc -z -w 10 "$SERVER_HOST" "$SERVER_PORT"; do
if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then
echo "Temporal server port did not become available after $MAX_ATTEMPTS attempts"
exit 1
fi
echo "Temporal server port not ready yet, waiting... (attempt $attempt/$MAX_ATTEMPTS)"
attempt=$((attempt + 1))
sleep "$SLEEP_SECONDS"
done
echo 'Temporal server port is available'
echo 'Waiting for Temporal server to be healthy...'
attempt=1
while :; do
if temporal operator cluster health --address "$TEMPORAL_ADDRESS"; then
break
fi
if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then
echo "Server did not become healthy after $MAX_ATTEMPTS attempts"
exit 1
fi
echo "Server not ready yet, waiting... (attempt $attempt/$MAX_ATTEMPTS)"
attempt=$((attempt + 1))
sleep "$SLEEP_SECONDS"
done
echo "Server is healthy, creating namespace '$NAMESPACE'..."
attempt=1
while :; do
if temporal operator namespace describe -n "$NAMESPACE" --address "$TEMPORAL_ADDRESS" >/dev/null 2>&1; then
echo "Namespace '$NAMESPACE' already exists"
break
fi
if temporal operator namespace create -n "$NAMESPACE" --address "$TEMPORAL_ADDRESS" >/dev/null 2>&1; then
echo "Namespace '$NAMESPACE' created"
break
fi
if [ "$attempt" -ge "$MAX_ATTdMPTS" ]; then
echo "Failed to create namespace '$NAMESPACE' after $MAX_ATTEMPTS attempts"
exit 1
fi
echo "Namespace operation not ready yet, waiting... (attempt $attempt/$MAX_ATTEMPTS)"
attempt=$((attempt + 1))
sleep "$SLEEP_SECONDS"
done