The SSH Session Management adds the possibility to end orphaned remote processes started by SSH Jobs or orphaned JobScheduler tasks from SSH Jobs.

Use Case

What happens if the connection to your remote host breaks while a script is still running? How can the JobScheduler job which started the remote script know about that?

What happens if a remote script has finished, but the JobScheduler task which started the process remotely cannot know about that (e.g. because of a temporarily broken network connection).

The SSH Session Management provides a solution for dealing with that type of issues: it provides the possibility of configuring an additional job chain to check for orphaned processes on the remote host as well as check for orphaned tasks.

You can configure your existing SSH job chain to start the monitoring job chain, which then will monitor the task of your original job chain as well as the processes started on the remote host via SSH.

Mode Of Operation

To configure your SSH Job to use the SSH Session Management you have to configure your SSH Job and define a cleanup job chain for the cleanup work.

Related Development Issues

Configuration of the SSH Job to be monitored

A number of additional parameters have to be added to the job configuration before the SSH Job can be monitored:

runWithWatchdog

format:

boolean

default value:

false

description:

If this parameter is set to true, the job itself is aware that it is monitored and generates an new order for the second job chain with all parameters of the job and the pid of the connected shell. If the parameter is set to false or is not present the SSH Session Management will not be processed.

cleanupJobchain

format:

String

default value:

empty

description:

This parameters defines the path to the configuration files of the job chain to use for the cleanup work.

ssh_job_kill_pid_command

format:

<command> \${pid}

default value:

kill -9 \${pid}

description:

The command to kill a process on the remote machine. The command depends on the OS of the remote host. If the command is not set, the cleanup job checks whether the remote host is running on a Linux or on a Windows system and uses the relevant appropriate commands.The ${pid} placeholder will be substituted by the cleanup job. Note that the leading $ character has to be escaped with "\".

ssh_job_terminate_pid_command

format:

<command> \${pid}

default value:

kill -15 \${pid}

description:

The command for terminating a process on the remote machine. This command depends on the OS of the remote host. If the command is not set, the cleanup Job checks whether the remote host is running on a Linux or on a Windows system and uses the appropriate default commands.The ${pid} placeholder will be substituted by the cleanup job. Note that the leading $ character has to be escaped with "\".

ssh_job_get_pid_command

format:

<command>

default value:

echo $$

description:

A command or script that writes the pid of the connected shell to stdout of the remote host.

ssh_job_get_child_processes_command

format:

<command> \${pid}

default value:

/bin/ps -ef | pgrep -P\${pid}

description:

The command or script determines the child processes of the given pid. The command or script depends on the OS of the remote host. The ${pid} placeholderswill be substituted by the cleanup job. Note that the leading $ character has to be escaped with "\".

ssh_job_get_active_processes_command

format:

<command> \${pid} \${user}

default value:

/bin/ps -ef | grep \${pid} | grep \${user} | grep -v grep

description:

The command or script checks if the process on the remote host is still running. The cleanup job expects an exitcode = 0 if the process is still running or other than 0 if the process is not available anymore. The command or script depends on the OS of the remote host. If the command is not set, the cleanup Job checks whether the remote host is running on a Linux or on a Windows system and uses the appropriate default commands. The ${pid} and ${user} placeholderswill be substituted by the cleanup job. Note that the leading $ character has to be escaped with "\".

Configuration Of The Cleanup Job Chain

A cleanup job chain with two jobs has to be configured to process the cleanup of the remote processes or the JobScheduler task.

The cleanup job chain consists of two jobs, one to read the pid of the connected shell from a temporary file on the remote host and one to check if the process or the JobScheduler Task is still running. The temporary file will be generated automatically and deleted after processing. The second job also ends either the remote process or the JobScheduler task as appropriate.

Job 1: The read-pid-from-temporary-file-Job

The first job reads the pid from the temporary file on the remote host. If your SSH Job is configured as described above, the temporary file will have been created automatically on the remote host.

Configure the Class of the Job in JOE like this:

After choosing the relevant class name from the list, configure a setback for the job. The setback will be used to restart the job according to the conditions found by the job (described above).

Job 2: The check-and-kill-Job

The second job checks if the pid determined by the first job is still active, if the JobScheduler Task is still active and kills the remote process or the JobScheduler task depending on the conditions found. The actions taken are described in the "Mode of Operation" section above.