Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • The job is configured with a timeout setting: if job execution exceeds the timeout then the job will be killed by the Agent.
  • Jobs can be killed by use of the GUI operation and and by use of the JS7 - REST Web Service API:
    • The cancelCancel/killKill operation kills a running job and fails the order.
    • The suspendSuspend/killKill operation kills a running job and suspends the order.
    • Failed and suspended orders can be resumed.

...

Code Block
languagebash
titleExample for Exit Trap on Script Termination
linenumberstrue
#!/bin/bash

# define trap for script completion
trap 'JS7TrapOnExit' EXIT

JS7TrapOnExit()
{
    rc=$?
    echo "($(date +%T.%3N)) $(basename $0): JS7TrapOnExit: waiting for completion of child processes ..."
    wait
    exit $rc
}

# create three child processes
sleep 100 &
sleep 110 &
sleep 120 &

# this is what the script normally should do:
#   echo "waiting for completion of child processes"
#   wait

echo "script completed"

...

  • Line 4: defines the trap calling the JS7TrapOnExit() function in case of the EXIT event. EXIT is a summary for a number of signals that terminate a script, however, this is available for the bash shell only. For use with other shells users instead have to state the list of signals such as TERM, INT etc.
  • Line 6 - 1012: implements the JS7TrapOnExit()function including the wait command to wait for termination of child processes or otherwise to immediately continue.
    • The exit code returned from the trap is reported by the task log and order log.
    • However, job execution will be considered failed independently from its the exit code value as the Cancel/Kill or Suspend/Kill operation was performed.
  • Line 15-17Line 13-15: starts background processes.
  • Line 19: 21 a script normally should wait for child processes, however, if this cannot be guaranteed, for example if set -e is used to abort a script in case of error, then use of a trap is an appropriate measure.

...