#! /bin/bash

DMACHINEMON_SERVENT=dmachinemon-servent
DMACHINEMON_MASTER=dmachinemon-master
PORTINTERNAL=$1
PORTEXTERNAL=$2
HOSTIP=$3

if [ -z "$HOSTIP" ] ; then
    cat <<EOF
$0 [temporal internal port number] [port that the server can be accessed] [HOSTIP]
    runs the dmachinemon daemon on cluster nodes using the
    internal port number to communicate to each other, and waits for
    client request at the specified port.

    HOSTIP needs to be the IP of the master node.
EOF
    exit 1
fi

dsh -a -c -M -- "$DMACHINEMON_SERVENT" -p "$HOSTIP" -n "$PORTINTERNAL" --sleep 15 -c "$PORTEXTERNAL" & "$DMACHINEMON_MASTER" -n "$PORTINTERNAL" -c "$PORTEXTERNAL"
