forked from isoprophlex/distributed-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-down.sh
More file actions
executable file
·63 lines (56 loc) · 2.15 KB
/
server-down.sh
File metadata and controls
executable file
·63 lines (56 loc) · 2.15 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
#!/bin/bash
# Define paths
ROOT_DIR=$(pwd)
CLUSTERS_DIR="$ROOT_DIR/clusters"
PG_CTL_DIR="$ROOT_DIR/src/bin/pg_ctl"
# If a parameter is provided, use it as the cluster name
if [ -n "$1" ]; then
DB_CLUSTER_NAME="$1"
else
# List available database clusters
echo "Available database clusters:"
clusters=()
for dir in $CLUSTERS_DIR/*/; do
if [[ "$dir" != "$CLUSTERS_DIR/config/" && "$dir" != "$CLUSTERS_DIR/contrib/" && "$dir" != "$CLUSTERS_DIR/doc/" && "$dir" != "$CLUSTERS_DIR/sharding/" && "$dir" != "$CLUSTERS_DIR/src/" ]]; then
clusters+=("$(basename "$dir")")
echo "$(basename "$dir")"
fi
done
# Determine if there is only one cluster available
if [ ${#clusters[@]} -eq 1 ]; then
DB_CLUSTER_NAME="${clusters[0]}"
echo "Only one cluster available. Automatically stopping: $DB_CLUSTER_NAME"
else
# Ask for the database cluster name to stop or stop all
read -p "Enter the name of the database cluster to stop (or type 'all' to stop all clusters): " DB_CLUSTER_NAME
fi
fi
# Stop all clusters if "all" is passed
if [ "$DB_CLUSTER_NAME" == "all" ]; then
# List all clusters
clusters=()
for dir in $CLUSTERS_DIR/*/; do
if [[ "$dir" != "$CLUSTERS_DIR/config/" && "$dir" != "$CLUSTERS_DIR/contrib/" && "$dir" != "$CLUSTERS_DIR/doc/" && "$dir" != "$CLUSTERS_DIR/sharding/" && "$dir" != "$CLUSTERS_DIR/src/" ]]; then
clusters+=("$(basename "$dir")")
fi
done
# Stop all clusters
for cluster in "${clusters[@]}"; do
DB_DIR="$CLUSTERS_DIR/$cluster"
echo "[SERVER-DOWN] Stopping PostgreSQL server for cluster $cluster..."
cd $PG_CTL_DIR
./pg_ctl -D $DB_DIR stop
echo "[SERVER-DOWN]Finished for cluster $cluster."
done
exit 0
fi
# Stop a specific cluster
DB_DIR="$CLUSTERS_DIR/$DB_CLUSTER_NAME"
if [ ! -d "$DB_DIR" ]; then
echo "[ERROR] The specified database cluster directory does not exist."
exit 1
fi
echo "[SERVER-DOWN] Stopping PostgreSQL server for cluster $DB_CLUSTER_NAME..."
cd $PG_CTL_DIR
./pg_ctl -D $DB_DIR stop
echo "[SERVER-DOWN] Finished for cluster $DB_CLUSTER_NAME."