#!/bin/bash

set -e

. ./CLUSTER-SERVER/_mongodb_cluster_common.bash

gs_mongodb_cluster_require_local_role \
    "router/orchestration" \
    "$GS_MONGODB_ROUTER_HOSTNAME"

echo "Starting config server ..."
gs_mongodb_cluster_remote_run \
    "$GS_MONGODB_CONFIG_SERVER_HOSTNAME" \
    RUN-MONGODB-CONFIG-SERVER-START.sh

echo "Starting shards ..."
for shard_host in "${GS_MONGODB_SHARD_HOSTNAMES[@]}"; do
    gs_mongodb_cluster_remote_run "$shard_host" RUN-MONGODB-SHARD-START.sh
done

echo "Starting router ..."
gs_mongodb_cluster_remote_run \
    "$GS_MONGODB_ROUTER_HOSTNAME" \
    RUN-MONGODB-ROUTER-START.sh

echo ""
./CLUSTER-SERVER/RUN-MONGODB-CLUSTER-STATUS.sh
