Skip to content

Commit

Permalink
Force login shell (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersy005 authored May 11, 2021
1 parent f453334 commit bf71707
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion jupyter_forward/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def start(
),
),
shell: str = typer.Option(
'/usr/bin/env bash',
'/usr/bin/sh -l',
'--shell',
'-s',
show_default=True,
Expand Down
23 changes: 19 additions & 4 deletions jupyter_forward/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RemoteRunner:
port_forwarding: bool = True
launch_command: str = None
identity: str = None
shell: str = '/usr/bin/env bash'
shell: str = '/usr/bin/sh -l'

def __post_init__(self):
console.rule('[bold green]Authentication', characters='*')
Expand Down Expand Up @@ -93,7 +93,18 @@ def __post_init__(self):

console.print('[bold cyan]:white_check_mark: The client is authenticated successfully')

def run_command(self, command, exit=True, warn=True, pty=True, hide=None, echo=True, **kwargs):
def run_command(
self,
command,
force_login_shell=False,
exit=True,
warn=True,
pty=True,
hide=None,
echo=True,
**kwargs,
):
command = f'sh -l -c "{command}"' if force_login_shell else command
out = self.session.run(command, warn=warn, pty=pty, hide=hide, echo=echo, **kwargs)
if out.failed:
console.print(f'[bold red] {out.stderr}')
Expand All @@ -106,10 +117,14 @@ def setup_port_forwarding(self):
console.rule('[bold green]Setting up port forwarding', characters='*')
local_port = int(self.port)
remote_port = int(self.parsed_result['port'])
remote_host = self.parsed_result['hostname']
console.print(
f'remote_host: {remote_host}, remote_port: {remote_port}, local_port: {local_port}'
)
with self.session.forward_local(
local_port,
remote_port=remote_port,
remote_host=self.parsed_result['hostname'],
remote_host=remote_host,
):
time.sleep(
3
Expand Down Expand Up @@ -186,7 +201,7 @@ def _launch_jupyter(self):
command = f'{self.launch_command} {script_file}'

console.rule('[bold green]Launching Jupyter Lab', characters='*')
self.session.run(command, asynchronous=True, pty=True, echo=False)
self.session.run(f'sh -l -c "{command}"', asynchronous=True, pty=True, echo=True)

# wait for logfile to contain access info, then write it to screen
condition = True
Expand Down

0 comments on commit bf71707

Please sign in to comment.