#!/bin/bash
#
#  mngprc.bash - Manage Job Processors
#
#  Zeno Job Server                                                     
#  Copyright (C) 2005  Scott Auge, Amduus Information Works, Inc.      
#                                                                      
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or   
#  (at your option) any later version.                                 
#                                                                      
#  This program 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 General Public License for more details.                        
#                                                                      
#  You should have received a copy of the GNU General Public License   
#  along with this program; if not, write to                           
#                                                                      
#  Free Software Foundation, Inc.                                      
#  59 Temple Place, Suite 330                                          
#  Boston, MA  02111-1307  USA                                         
#                                                                      
#                                                  

##############################################################################
# Get our environment here...                                                #
##############################################################################

. ./set.bash

##############################################################################
# No arguments means the user needs a reminder of the arguments              #
##############################################################################

if [ $# -eq 0 ]
then

  echo $0
  echo "-start         Start the processor (requires -prcname)"
  echo "-stop          Stop a processor (requires -hostname -hostpid "
  echo "               or -hostname -prcname)"
  echo "-clean         Clean dead records (requires -tosubmitdate or "
  echo "               -toprcstopdate)"
  echo "-hostname      Specify the host the command should appeal to"
  echo "-hostpid       Specify the PID of the process to send the command to"
  echo "-prcname       Name the service the processor provides"
  echo "-tosubmitdate  Used for -clean to delete records submitted up"
  echo "               to and including this date"
  echo "-toprcstopdate Used for -clean to delete records cleanly processed"
  echo "               up to and including this date."
  echo "-pause         Amount of time to pause between job runs (throttle)"
  echo

  exit 1

fi

##############################################################################
# Interprete arguments into environmental variables we can use OS-GETENV()   #
# against to communicate the user's intention to the 4GL code.               #
##############################################################################

for i in $@
do

  ########################################################################
  # Handle our argumentless switches                                     #
  ########################################################################

  case $i in

     -start)
       export PRCCMD="start"
       ;;

     -stop)
       export PRCCMD="stop"
       ;;
       
     -clean)
       export PRCCMD="clean"
       ;;

  esac

  ########################################################################
  # Handle our switches with arguments                                   #           
  ########################################################################

  case $lastcmd in

     -pause)
       export PRCPAUSE=$i                     
       ;;
       
     -hostname)
       export PRCHOSTNAME=$i
       ;;
     
     -hostpid)
       export PRCHOSTPID=$i
       ;;

     -prcname)
       export PRCNAME=$i
       ;;
       
     -toprcstopdate)
       export TOSTOPDATE=$i
       ;;
                                                                                         
     -tosubmitdate)
       export TOSUBMITDATE=$i
       ;;                                                       
                                              
  esac

  lastcmd=$i

done

##############################################################################
# Hit the job server procedure to implement what is requested.               #
##############################################################################

$DLC/bin/_progres -b -pf $PFFILE -p jobsvr.p

                                           
