Versions Compared

Key

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

...

  • When the respective OS signal is received then the current command of the job shell script is aborted and instead the trap is executed.
    • This is why you find two trap definitions with the above example:
      • When cancelling a job then the SIGTERM signal is sent by the Agent to the process running the job shell script.
      • As the job shell script process spawns another shell script to be executed in background the trap in line 4 of the above example is added:
        • the job shell script's trap forwards the SIGTERM signal to the sample shell script.
        • the sample shell script defines its own trap with line 36 that receives the job shell script's signal.
  • After execution of the trap the sample shell script is resumed with the next command after line 44. 
    • The assumption is that the SIGTERM signal is received while waiting for the sleep command to be completed with line 44.
    • With the wait command being interrupted the cleanupTermporaryFiles() function is called by the sample shell script with line 47.
  • As a result the sample shell script is completed with line 49 and control is returned to the job shell script that continues with the line following the wait command in line 59 that basically exits the job shell script and provides the exit code of the most recently executed command.
    • This exit code is informational only as the Agent will set the job's exit code to the value 1 to indicate failure of the job independently from the trap being completed successfully or not.

Further Resources