#!/bin/bash

set -e

. ./CLUSTER-SERVER/_mongodb_cluster_common.bash

roles=0

if gs_mongodb_cluster_host_is_local "$GS_MONGODB_CONFIG_SERVER_HOSTNAME"; then
    ./CLUSTER-SERVER/RUN-MONGODB-CONFIG-SERVER-START.sh
    roles=$((roles + 1))
fi

if gs_mongodb_cluster_find_local_shard >/dev/null 2>&1; then
    ./CLUSTER-SERVER/RUN-MONGODB-SHARD-START.sh
    roles=$((roles + 1))
fi

if gs_mongodb_cluster_host_is_local "$GS_MONGODB_ROUTER_HOSTNAME"; then
    ./CLUSTER-SERVER/RUN-MONGODB-ROUTER-START.sh
    roles=$((roles + 1))
fi

[ "$roles" -gt 0 ] ||
    gs_mongodb_die "The current host has no server role in the cluster setup."
