Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a wrapper to the processes executed over ssh #337

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ console_scripts =
drunc-unified-shell = drunc.apps.__main_unified_shell__:main
drunc-fsm-tests = drunc.tests.__main_fsm__:main
application-registry-service = drunc.apps.__main_app_connectivity_server__:main
drunc-ssh-validator = drunc.apps.__main_ssh_validator__:main
drunc-ssh-validator = drunc.apps.__main_ssh_validator__:main
drunc-ssh-process-wrapper = drunc.apps.__main_ssh_process_wrapper__:main
33 changes: 33 additions & 0 deletions src/drunc/apps/__main_ssh_process_wrapper__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import signal
import os
import time
import subprocess
import click

def terminate_all(sig, frame):
print('')
pgrp = os.getpgid(os.getpid())
os.killpg(pgrp, signal.SIGKILL)


@click.command()
@click.argument("cmd")
@click.option("-l", "--log", "log_path", type=click.Path(file_okay=True, dir_okay=False))
def launch(cmd: str, log_path: str):
signal.signal(signal.SIGHUP, terminate_all)

with open(log_path, 'w') as logfile:
proc = subprocess.Popen(cmd, shell=True, stdout=logfile, stderr=logfile)
print(f"Started process with pid {proc.pid}")

return_code = None
while True:
return_code = proc.poll()
if return_code is not None:
break
time.sleep(0.1)



if __name__ == '__main__':
launch()
2 changes: 1 addition & 1 deletion src/drunc/process_manager/ssh_process_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def __boot(self, boot_request:BootRequest, uuid:str) -> ProcessInstance:
if cmd[-1] == ';':
cmd = cmd[:-1]

arguments = [user_host, "-tt", "-o StrictHostKeyChecking=no", f'{{ {cmd} ; }} &> {log_file}']
arguments = [user_host, "-tt", "-o StrictHostKeyChecking=no", f'{cmd_env} drunc-ssh-process-wrapper --log {log_file} {cmd}']
self.log.debug(f"{arguments}")
# arguments = [user_host, "-tt", "-o StrictHostKeyChecking=no", f'{{ {cmd} ; }} > >(tee -a {log_file}) 2> >(tee -a {log_file} >&2)']
# I'm gonna bail now and read that log file, anyway, it's probably better that heavy logger applications don't clog up the process manager CPU.
Expand Down
Loading