Versions Compared

Key

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

...

  • Jobs are executed with JS7 Agents that which handle termination of jobs.
    • Shell Jobs and JVM Jobs are under Control of the Agent that Agent which terminates running jobs.
    • Jobs implementing use of an SSH Client or use of the JS7 - JITL SSHJob cannot guarantee that a job's child processes are terminated as they are controlled by the remote SSHD server.
  • Termination of jobs can be caused by users from the JOC Cockpit and can performed automatically if jobs exceed a given timeout.
    • As a prerequisite for termination by the JOC Cockpit, the Controller has to be connected to the JOC Cockpit and the Agent has to be accessible to the Controller.
  • See 
    Jira
    serverSOS JIRA
    columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
    serverId6dc67751-9d67-34cd-985b-194a8cdc9602
    keyJS-1965

...

  • 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 using the GUI operation and and by use of the JS7 - REST Web Service API:
    • The Cancel/Kill operation kills a running job and fails the order.
    • The Suspend/Kill operation kills a running job and suspends the order.
    • Failed and suspended orders can be resumed.

Terminating Jobs on Unix

In Unix environments, jobs receive the following signals from the Agent:

  • When a job should is to be killed then the Agent first sends a SIGTERM signal.
    • This signal can be ignored or it can be handled by a job. For shell scripts a trap can be defined to e.g. , for example, perform cleanup tasks such as disconnecting from a database or removing temporary files.
  • The job configuration includes the Grace timeout setting:
    • The Grace Timeout duration is applied after a SIGTERM signal (corresponding to kill -15) has been sent by the Agent. This allows the job to terminate on its own, for example after some cleanup is has been performed.
  • Should the job still run be running after the specified Grace Timeout duration then the Agent sends will send a SIGKILL signal (corresponding to kill -9) that aborts the OS process.

...

Job scripts frequently spawn child processes that have to be killed accordingly to in line with their parent process.

  • By default the OS removes child processes if the parent process is killed. However, this mechanism is not applicable for all situations, depending on the way how child processes have been spawned.
  • In order to more reliably kill child processes the Agent makes use of uses the kill_task.sh script from its var_<port>/work directory.
    • This script identifies the process tree created by the job script and kills any available child processes.
    • Download: kill_task.sh
  • Though the Agent is platform independent it is evident that retrieval of a process tree does not necessarily use the same command (ps) and options for any all Unixes.
    • The Agent therefore allows to specify specification of an individual kill script from a command line option should if the built-in kill_task.sh script is not be applicable to your Unix platform, see JS7 - Agent Operation.

...

In a situation when a Shell Job script starts a background process and does not wait for termination of the child process but instead completes (with our or without error), then the Agent cannot identify the running child process as its parent process is has gone. It is therefore recommended to add that a trap is added to the shell script that is . This will be triggered on termination of the script - independently from the fact that of whether the script terminates normally or with an error. This prevents the script from terminating immediately with while child processes are running. Instead, in case the event of forced termination, the script continues will continue due to its trap waiting for child processes and the Agent executes will execute the kill_task.sh script that . This script identifies the process of the Shell Job script process and kills the running child processes.

Download: jduExitTrap.json

...

  • Line 3 - 11: implements the JS7Trap()function including the wait command to wait . This either waits for termination of child processes or otherwise to continues immediately continue.
    • The exit code returned from the trap in case the event of script termination is reported by the task log and order log.
    • However, job execution will be considered failed independently from the to have failed regardless of the exit code value as the Cancel/Kill or Suspend/Kill operation was has been performed.
  • Line 14-16: define traps calling the JS7Trap() function in case of receipt the event of the following signals being received:
    • EXIT is a summary for a number of signals that terminate a script, however, this is available for the bash shell only.
    • SIGTERM is the termination signal sent by the Agent if the Cancel/Kill or Suspend/Kill operation is invoked.
    • SIGINT is added in case that OS processes external to the JS7 Agent would send this signal, that which usually corresponds to hitting Ctrl+C in a terminal session.
  • Line 15-17: starts background processes.
  • Line 21 a script should normally should wait for child processes, however. However, if this cannot be guaranteed, for example if set -e is used to abort a script in case of error, then the use of a trap is an appropriate measure.
  • The following sequence of actions is performed:
    • The above job script listed above does not wait for child processes and therefore terminates triggering the EXIT pseudo-signal. The trap function is executed and waits for child processes to be completed. During this period the task process for the job remains alive.
    • If subsequently the Cancel/Kill or Suspend/Kill operation is invoked, then the Agent sends will send a SIGTERM signal thatwhich:
      • interrupts the wait command in the currently executed JS7Trap()function,
      • triggers once more execution of the JS7Trap()function once more and performs the wait operation for child processes.
    • Having applied the Grace Timeout the Agent executes the kill_task.sh script that which sends a STOP signal to the task process, kills any child processes and finally sends a SIGKILL signal to abort the task process.
    • The crucial point is that the job script would does not terminate with child processes running but remains active due to triggering of a trap that which allows the Agent to kill any child processes from the process tree. If the task process for the job script terminates with child processes running then the Agent cannot identify the process tree and cannot kill child processes.

Automation of Exit Traps

JS7 offers provides an option to apply for applying traps such as from those described in the example above example . These can be applied to a number of Shell Job scripts via JS7 - Script Includes.

...

For Windows environments the following applies when terminating jobs:

  • The Agent makes use of uses the kill_task.cmd script that which is available from its var_<port>/work directory.
    • The script makes use of uses the taskkill command to kill the job's process and its children.
    • Download: kill_task.cmd
  • An individual kill script can be specified with a command line option on Agent startup, see JS7 - Agent Operation.

...