#!/bin/bash

# this script dispatches marmaserver launch to local or remote MC cores

function usage
{
    echo "usage: launch-marmaserver {dhcp|static} [static ip address]"
}

MODE=${1}
IPADDRESS=${2}
STARTUP_SCRIPT=/opt/midas/bin/startup-marmaserver

echo "triggering launch of marmaserver, mode=${MODE} ip address=${IPADDRESS}"

if [ "`hostname`" == "MC-1" ]; then
    ${STARTUP_SCRIPT} ${MODE} ${IPADDRESS} &
else
    ssh MC-1 "${STARTUP_SCRIPT} ${MODE} ${IPADDRESS}" &
fi

# don't do this for DL1/2 (only XL8/DL3 have bonded network ports, PROX has a different port naming)
if [ -n "`ip addr | grep inet | grep bond0`" ]; then
    if [ "`hostname`" == "MC-2" ]; then
        ${STARTUP_SCRIPT} ${MODE} ${IPADDRESS}
    else
        ssh MC-2 "${STARTUP_SCRIPT} ${MODE} ${IPADDRESS}"
    fi
fi

