#! /bin/bash

# This script stops the rapid file transfer.
#
# It finds the process ID for the process
# If a process is not located this terminates.
# The "stop file" for this process is determined from the
#    configuration file.
# stop_loading is invoked with suitable arguments.
#
# Usage: /opt/cyflex_java/cmds/stop_rapid_transfers
#
# Author: Rob Janes
#
# History
#   07/16/15 - Rob Janes - Initial release.
#   09/13/16 - Joe Suever - Modified Indicom PC version to work on CyFlex 
#   10/06/16 - Nareeya Kaewfanapadon - Modified from stop_sftp_transfers
#   12/23/24 - Rob Janes - Added to cyflex_java as standard process.

# This requires 1 command line argument, an existing configuration file.
if (( $# != 1 )); then
   echo This program requires one command line argument, the spec file.
   exit 1
fi
if [ ! -e $1 ]; then
   echo The command line argument must be an existing file.
fi

PROG=com.cybermetrix.cyflex.extdatman.SftpTransferExtDatMan
FILE=$1
# Find the PID for this process.
PID=$(ps -ef | grep $PROG | grep $FILE | grep -v grep | tr -s ' ' | cut -f2 -d\ )
# If PAM / DARTS isn't running, no need to stop it.
if [ "$PID" = "" ]; then
   exit 0
fi

# File the stop file name.
STOP_FILE=`grep cyflex.extdatman.stopFile $FILE | cut -f2 -d\  `

# Invoke the common stopping script.
stop_loading $PID $STOP_FILE 60 5
