#!/bin/ksh93

#/* Part of the Maestro sequencer software package.
# * Copyright (C) 2011-2015  Operations division of the Canadian Meteorological Centre
# *                          Environment Canada
# *
# * Maestro is free software; you can redistribute it and/or
# * modify it under the terms of the GNU Lesser General Public
# * License as published by the Free Software Foundation,
# * version 2.1 of the License.
# *
# * Maestro is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# * Lesser General Public License for more details.
# *
# * You should have received a copy of the GNU Lesser General Public
# * License along with this library; if not, write to the
# * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# * Boston, MA 02111-1307, USA.
# */


#simple script to check the status of the mserver on a given machine, then launch an mserver on a target machine if it is not currently online. 
arguments=$*

eval `cclargs $0 "[Simple script to check the status of the mserver on a given machine, then launch an mserver on a target machine if it is not currently online.]" \
  -m        ""                    "$TRUE_HOST"                 "[Machine on which to launch server ]" \
  -v        ""                    "1"                          "[Verbose            ]" \
  -h        ""                    ""                           "[Display help       ]" \
  ++ $arguments` 


if [[ $v != "" ]] ; then  
  set -x
fi 

ping -q -c 1 $m || exit 1
[[ $(madmin -i) ]] ||  ssh  $m  -t bash -l -c \"$SEQ_MAESTRO_SHORTCUT\; export SEQ_MAESTRO_SHORTCUT=\'$SEQ_MAESTRO_SHORTCUT\'\; mserver\"  

