#!/bin/sh
#
# A simple script to help startup a Fida application. It starts up the application if
# it isn't already running.  This script can be used as a cron job.

# Change these three values according to your installation.
# client       is the name of the client executable
# client_path  is the path to the directory containing the client binary
# num_clients  is the number of clients to be run on the machine (possibly 2 for a dual processor)

client=client
client_path=~/eon_client/
num_clients=2

# check for currently running clients
for pids in `/sbin/pidof ${client_path}${client}`; 
  do num_clients=$[${num_clients}-1]; 
done

new_clients=0
if test ${num_clients} -ne 0; then
  new_clients=1
  echo "Starting ${num_clients} clients."
fi

# start up to num_clients
while test ${num_clients} -ne 0;
  do 
  echo "Starting client..."     
  num_clients=$[${num_clients}-1]
  cd ${client_path};
  (${client} > /dev/null  &);
done

# nice the clients
if test ${new_clients} -ne 0; then
  for pids in `/sbin/pidof ${client_path}${client}`; 
    do renice 20 -p ${pids} 
  done
fi
