#!/bin/sh

if [ $# -lt 1 ]; then
  echo "Usage: `basename $0` <start|stop|stat> [execworker args]"
  exit 1
fi

cmd=$1; shift

if [ "$cmd" == "start" ]; then
  if [ $# != 2 ]; then
    echo "Usage: `basename $0` start <host: e.g., r23, nlp> <instance: e.g., 1, 2, 3, 4>"
    exit 1
  fi
  execworker "$@" >& /dev/null &
elif [ "$cmd" == "stop" ]; then
  echo "Killing `ps --noheaders -C execworker | wc -l` execworker processes"
  killall -g execworker 2> /dev/null
elif [ "$cmd" == "stat" ]; then
  ps --noheaders -C execworker -o pid,cmd
else
  echo "Invalid command: $cmd"
fi
