ssh_process_lifetime_manager_shell
drunc.processes.ssh_process_lifetime_manager_shell
Provides SSH connection and lifetime management using sh library.
This implementation uses the sh library to execute SSH commands, replicating the behaviour of the original SSHProcessManager.
Classes
ProcessWatcherThread(uuid, process, on_exit, logger)
Bases: Thread
Thread that monitors a background SSH process and invokes callback on exit.
Initialise process watcher thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to monitor |
required |
process
|
RunningCommand
|
sh.RunningCommand instance to monitor |
required |
on_exit
|
Optional[Callable[[str, Optional[int], Optional[Exception]], None]]
|
Callback function invoked on process exit |
required |
logger
|
Logger
|
Logger instance for output |
required |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
Functions
run()
Monitor process and invoke callback on exit.
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
SSHProcessLifetimeManagerShell(disable_host_key_check=False, disable_localhost_host_key_check=False, logger=None, on_process_exit=None)
Bases: ProcessLifetimeManager
Manages process lifecycle using sh library for SSH connections.
This implementation uses the sh library's SSH command wrapper to start and manage remote processes, matching the behaviour of the original SSHProcessManager implementation.
Initialise SSH process lifetime manager using sh library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disable_host_key_check
|
bool
|
Disable SSH host key verification for all hosts |
False
|
disable_localhost_host_key_check
|
bool
|
Disable SSH host key verification for localhost |
False
|
logger
|
Optional[Logger]
|
Logger instance for real-time output logging |
None
|
on_process_exit
|
Optional[Callable[[str, Optional[int], Optional[Exception]], None]]
|
Optional callback function(uuid, exit_code, exception) invoked when process exits |
None
|
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
Functions
cleanup_all()
Clean up all processes and resources.
Terminates all managed processes and releases all associated resources.
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
cleanup_process(uuid)
Clean up process resources.
Terminates the process (if still running) and releases all associated resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to clean up |
required |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
get_active_process_keys()
Get list of active process UUIDs.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of active process UUID strings |
get_exit_code(uuid)
Get process exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Exit code if process has terminated, None if still running or not found |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
get_process_stderr(uuid)
Get stderr from process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Accumulated stderr content as string, None if not found |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
get_process_stdout(uuid)
Get stdout from process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Accumulated stdout content as string, None if not found |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
is_process_alive(uuid)
Check if process is alive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if process is alive, False otherwise |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
read_log_file(hostname, user, log_file, num_lines=100)
Read remote log file via SSH.
Creates a temporary SSH connection to read the log file and returns the last N lines using the tail command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
Target hostname |
required |
user
|
str
|
SSH username |
required |
log_file
|
str
|
Remote log file path |
required |
num_lines
|
int
|
Number of lines to read from end of file |
100
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of log lines |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 | |
start_process(uuid, boot_request)
Start a remote process via SSH using the boot request configuration.
Extracts all necessary parameters from the boot request and executes the process on the remote host using sh library's SSH wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Unique identifier for this process |
required |
boot_request
|
BootRequest
|
BootRequest containing process configuration, metadata, environment variables, and execution parameters |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If SSH connection or process execution fails |
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
terminate_process(uuid, timeout=10.0)
Terminate process by sending signals.
Sends SIGQUIT followed by SIGKILL if necessary, with the configured timeout between signals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to terminate |
required |
timeout
|
float
|
Timeout between signals in seconds |
10.0
|
Source code in drunc/processes/ssh_process_lifetime_manager_shell.py
validate_host_connection(host, auth_method, user=getpass.getuser())
Validate SSH connection to the specified host.
Attempts to establish an SSH connection to the host and execute a simple echo command to verify connectivity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Target hostname |
required |
auth_method
|
str
|
Authentication method (not used in sh implementation) |
required |
user
|
str
|
SSH username (default: current user) |
getuser()
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If SSH connection or command execution fails |