Display feature availability |
---|
|
Status |
---|
colour | Yellow |
---|
title | under construction |
---|
|
Mode Of Operation
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.
Anchor |
---|
| mode_of_operation |
---|
| mode_of_operation |
---|
|
Mode of OperationTo configure your SSH job to To use the SSH Session Management you have to configure your SSH Job job and define a second jobchain cleanup job chain for the cleanup work.
Ths feature is available only with The feature requires the use of the JSch implementation by JCraft. To configure your SSH Job See How To - Usage of the SSH Job (JobSchedulerSSHJob) with JCraft's JSch for more information about configuring your SSH job to use the JSch implementation, see How To - Usage of the SOSSSHJob2JSAdapter Job with JCrafts JSch .
Adjust the SSH Job to be monitored
To be able to monitor the SSH Job you have to add some additional parameters to the job configuration.
runWithWatchdog
The SSH Session Management will carry out one of the following actions after checking the remote processes and JobScheduler tasks:
- if a remote process is running and the JobScheduler task is still alive:
- do nothing, the cleanup job chain goes to a setback condition and waits for another start
- if a remote process is running but the JobScheduler task is no longer available:
- the cleanup job tries to end the process on the remote host
- if a remote process is no longer available but the JobScheduler task is still running:
- the cleanup job ends the task immediately
- if a remote process and the JobScheduler task are not available anymore
- do nothing, the cleanup job ends
Related Development Issues
Jira |
---|
server | SOS JIRA |
---|
columns | key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | JITL-152 |
---|
|
Jira |
---|
server | SOS JIRA |
---|
columns | key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | JITL-147 |
---|
|
Jira |
---|
server | SOS JIRA |
---|
columns | key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | JITL-123 |
---|
|
Jira |
---|
server | SOS JIRA |
---|
columns | key,summary,type,created,updated,due,assignee,reporter,priority,status,resolution |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
key | JITL-112 |
---|
|
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:format:
- default value:
- description:
- If this parameter is set to true, the job itself is aware that it is monitored and generates an a new order for the second jobchain with 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:
- path to the configuration files of the jobchainstring
- default value:
- description:
- This parameters defines the jobchain the path to the configuration files of the job chain to use for the cleanup work.
ssh_job_kill_pid_command
- format:
- default value:
- 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 job checks whether the remote host if it runs is running on a Linux or on a Windows system and uses the related default relevant appropriate commands.
The placeholder ${pid}
will placeholder will be substituted by the cleanup job and . Note that the leading $ character has to be escaped with "\".
ssh_job_terminate_pid_command
- format:
- default value:
- description:
- The command to terminate for terminating a process on the remote machine. The This command depends on the OS of the remote host. If the command is not set, the cleanup Job job checks whether the remote host if it runs is running on a Linux or Windows and on a Windows system and uses the related appropriate default commands.
The placeholder ${pid}
will placeholder will be substituted by the cleanup job and . Note that the leading $ character has to be escaped with "\".
ssh_job_get_pid_command
- format:
- default value:
- 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:
- 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. If the command is not set, the default command for Linux is used.
The ${pid}
placeholders will 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 default command for Linux is used.
The ${pid}
and ${user}
placeholders will be substituted by the cleanup job. Note that the leading $ character has to be escaped with "\". - Example commands:
/bin/ps -ef
- writes all running processes to stdout on the remote host
| grep \${pid}
- filters the result to show only results containing the given ${pid}
| grep \${user}
- filters the result to show only results containing the given ${user}
| grep -v grep
- filters the grep command itself
Example: Configuration with JOE
Job
Image Added
Parameters
Image Added
Example: XML Configuration
Code Block |
---|
|
<job title="Launch commands or executable files by SSH">
<description>
<include file="jobs/JobSchedulerSSHJob.xml"/>
</description>
<params>
<param name="host" value="[HOST]"/>
<param name="port" value="[SSHPORT]"/>
<param name="user" value="[USERNAME]"/>
<param name="password" value="[PASSWORD]"/>
<param name="auth_method" value="password"/>
<param name="command_script_file" value="[PATH_TO_SCRIPTFILE]\test_sleep_90s.sh"/>
<param name="runWithWatchdog" value="true"/>
<param name="cleanupJobchain" value="kill_jobs/remote_cleanup_test"/>
<param name="ssh_job_kill_pid_command" value="kill -9 \${pid}"/>
<param name="ssh_job_terminate_pid_command" value="kill -15 \${pid}"/>
<param name="ssh_job_get_pid_command" value="echo $$"/>
<param name="ssh_job_get_active_processes_command" value="/bin/ps -ef | grep \${pid} | grep \${user} | grep -v grep"/>
</params>
<script java_class="sos.scheduler.job.SOSSSHJob2JSAdapter" language="java"/>
<run_time/>
</job> |
Anchor |
---|
| config_second_job_chain |
---|
| config_second_job_chain |
---|
|
Configuration of the Cleanup job chainA 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:
Image Added
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).
Image Added
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
- kills the remote process or the JobScheduler task
depending on the conditions found. The actions taken are described in the Mode of Operation chapter above.
Configure the class of the job in JOE as follows:
Image Added
Example: XML Configuration
Code Block |
---|
language | xml |
---|
title | Job1: ReadPidFileJob |
---|
collapse | true |
---|
|
<job order="yes" stop_on_error="no" title="Launch read pid file command by SSH">
<description>
<include file="jobs/SOSSSHReadPidFileJob.xml"/>
</description>
<script java_class="sos.scheduler.job.SOSSSHReadPidFileJobJSAdapter" language="java"/>
<delay_order_after_setback delay="30" is_maximum="no" setback_count="1"/>
<delay_order_after_setback delay="0" is_maximum="yes" setback_count="3"/>
<run_time/>
</job> |
Code Block |
---|
language | xml |
---|
title | Job2: CheckAndKillJob |
---|
collapse | true |
---|
|
<job order="yes" stop_on_error="no" title="Kills orphaned PIDs on the Remote Host for clean up by SSH">
<description>
<include file="jobs/SOSSSHKillJob.xml"/>
</description>
<script java_class="sos.scheduler.job.SOSSSHKillJobJSAdapter" language="java"/>
<delay_order_after_setback delay="30" is_maximum="no" setback_count="1"/>
<delay_order_after_setback delay="0" is_maximum="yes" setback_count="3"/>
<run_time/>
</job> |
Code Block |
---|
language | xml |
---|
title | Jobchain: Cleanup |
---|
collapse | true |
---|
|
<job_chain orders_recoverable="yes" visible="yes">
<job_chain_node error_state="ERROR" job="readPidFile" next_state="CheckTaskAndRemoteProcessesAndKillIfNeeded" on_error="setback" state="ReadPidFile"/>
<job_chain_node error_state="ERROR" job="CheckAndKill" next_state="SUCCESS" on_error="setback" state="CheckTaskAndRemoteProcessesAndKillIfNeeded"/>
<job_chain_node state="ERROR"/>
<job_chain_node state="SUCCESS"/>
</job_chain> |
Change Management References
Jira |
---|
server | SOS JIRA |
---|
columns | type,key,issuelinks,fixversions,status,priority,summary,updated |
---|
maximumIssues | 20 |
---|
jqlQuery | labels in (ssh) |
---|
serverId | 6dc67751-9d67-34cd-985b-194a8cdc9602 |
---|
|