is there an obvious way to exec/drop to a raw tty ...
# atmos
m
is there an obvious way to exec/drop to a raw tty via a custom command? E.g. I'm trying to do something like:
Copy code
commands:
  name: ssh
  steps:
    - type: shell
      output: raw
      command: "exec aws ssm start-session --target {{ .Arguments.instance_id }}"
but the exec seems to be within a subprocess itself, so doesn't replace atmos and the terminal gets all bunged up, most obviously if you try and Ctrl-C a command in the session, atmos itself takes teh Ctrl-C exits, and then the session ends with SIGPIPE šŸ˜ž Feels like a common need I would have thought, but I'm failing to find the right invocation in the docs...
e
Aha, very cool use-case
I think we might want to introduce flags similar to docker: •
tty
•
interactive
I'll whip something up and get that into the next release.
When CI completes, you can try
Copy code
atmos --use-version=2602 ...
https://github.com/cloudposse/atmos/pull/2602
m
nice,thanks! will give it a whirl later today
seems to mostly work (e.g. Ctrl-C makes it to the remote shell). two nits: 1. once the ssh terminates (e.g. Ctrl-D) the tty doesn't return to the command-prompt until you Ctrl-C again 2. once you do get back to the shell, state is weird (no echo most notably), needs a reset/clear before usable again. seems like some missing clean-up after the step command has terminated perhaps?
Copy code
matt@argon:~/mkmba/cloud-infra$ atmos --use-version=2602 ssh --identity dev-ocopt i-0a...
āœ“ PR #2602 is up to date (sha: 8fd822b)
āœ“ Switching to Atmos version 2602

Starting session with SessionId: matt@...
sh-5.2$ ^C
sh-5.2$
exit


Exiting session with sessionId: matt@...

matt@argon:~/mkmba/cloud-infra$
/home/matt/mkmba/cloud-infra
(I hit Ctrl-C again after the "exiting session with.." text to get back to the prompt; and then typed 'pwd' which wasn't echoed.
e
Ok, that's a good repro test
Fix was pushed and seems to work for me
But if you want to use the command above, you'll need to wait for the build to complete
m
progress... I'm getting sha a350fd0, if I connect and then exit immediately, I get back to the prompt swiftly and ther terminal seems to be in a good state. If I exit after having sent a Ctrl-C or similar in the session than I still see the old hang behaviour, rather than returning to the prompt - but if I press Enter, that seems to do something and about 3-5s later atmos exits with "*Error:* subcommand exited with code -1" - terminal is in a good state. If I hit Ctrl-C during the hang, rather than enter, then immediate exit with terminal in a bad state.
e
Are you on Mac?
m
linux, ghostty on arch, ssh'd into an ubuntu box where atmos is running; bash as the shell on both machines.
šŸ‘ 1
e
I pushed one more fix. I can no longer reproduce it. šŸ¤ž
@Matt Brown If you get the chance to test this out, let me know so we can get it into the next release
m
will do, had a busy day yesterday, but should be able to find some time in the next few hours.
šŸ™ 1
Hmm, I'm seeing a regression back to the pre-fix behaviour entirely on the latest version it's pulling down (e.g. Ctrl-C immediately closes the session with SIGPIPE) - is 887a988 the right version to be testing?
Copy code
matt@argon:~/mkmba/cloud-infra$ atmos --use-version 2602 ssh --identity dev-ocopt i-0d315f6f53616a157
āœ“ PR #2602 is up to date (sha: 887a988)
āœ“ Switching to Atmos version 2602

Starting session with SessionId: <mailto:matt@mkmba.nz|matt@mkmba.nz>-jreklqgdksy3jc7v9txls74g6a
sh-5.2$ matt@argon:~/mkmba/cloud-infra$
aws: [ERROR]: Command '['session-manager-plugin', 'AWS_SSM_START_SESSION_RESPONSE', 'ap-southeast-2', 'StartSession', '', '{"Target": "i-0d315f6f53616a157"}', '<https://ssm.ap-southeast-2.amazonaws.com>']' died with <Signals.SIGPIPE: 13>.
e
Copy code
base_path: "."

logs:
  level: Info

commands:
  # 1. Basic terminal session (the SSM stand-in).
  #    Expect: a bash prompt; full-screen apps render; exit/Ctrl-D returns you
  #    to your own shell immediately with echo working.
  - name: test-tty
    description: Interactive bash in a tty step (SSM session stand-in)
    steps:
      - type: shell
        tty: true
        interactive: true
        command: "bash --norc -i"

  # 2. Matt's repro - grandchild keeps the PTY open after the session exits
  #    (this is what aws ssm's session-manager-plugin does).
  #    Expect WITH the fix: after `exit`, your prompt is back within ~1 second
  #    and echo works. WITHOUT the fix: hang until a keypress, then no echo.
  - name: test-lingering
    description: Reproduce the SSM teardown hang (background child holds the PTY)
    steps:
      - type: shell
        tty: true
        interactive: true
        command: "sleep 60 & bash --norc -i"

  # 3. Ctrl-C handling - press Ctrl-C while sleep runs.
  #    Expect: the sleep is interrupted (atmos exits 130 from the step), your
  #    terminal is sane afterwards. Atmos itself was NOT killed by the signal -
  #    it returned through normal teardown (terminal restored, exit code clean).
  - name: test-ctrlc
    description: Ctrl-C goes to the step, not atmos
    steps:
      - type: shell
        tty: true
        interactive: true
        command: "echo 'Press Ctrl-C now...'; sleep 30; echo 'not interrupted'"

  # 4. Interactive without tty - prompts work, output still masked/managed.
  - name: test-interactive
    description: Interactive (non-tty) step reads stdin
    steps:
      - type: shell
        interactive: true
        command: "printf 'type something: '; read x; echo \"you typed: $x\""

  # 5. exec step - replaces the atmos process entirely.
  #    Expect: `ps -o ppid= -p $$` inside the shell shows your TERMINAL's shell
  #    as parent (no atmos in the process tree - it was replaced). Ctrl-Z job
  #    control is native. Exit code propagates: run `exit 7`, then `echo $?`
  #    in your own shell shows 7.
  - name: test-exec
    description: Replace the atmos process (shell exec semantics)
    steps:
      - type: exec
        command: "bash --norc -i"

  # 6. Validation - exec must be the final step.
  #    Expect: immediate error, nothing executes.
  - name: test-exec-invalid
    description: Exec step not last - must fail validation
    steps:
      - type: exec
        command: "echo never runs"
      - type: shell
        command: "echo unreachable"

  # 7. Plain step - unchanged behavior (baseline).
  - name: test-plain
    description: Plain shell step (baseline, unchanged behavior)
    steps:
      - "echo plain step ok"

  # 8. Color self-test (non-interactive). tty:true allocates a PTY so the
  #    program sees a real terminal; color should render. Exits on its own.
  - name: test-color
    description: Print a color self-test inside a tty step
    steps:
      - type: shell
        tty: true
        command: |
          echo "TERM=$TERM"
          echo "tput colors: $(tput colors 2>/dev/null)"
          printf '\033[31mRED\033[0m \033[32mGREEN\033[0m \033[33mYELLOW\033[0m \033[34mBLUE\033[0m\n'
          printf '\033[1mBOLD\033[0m \033[4mUNDERLINE\033[0m \033[7mINVERSE\033[0m\n'
          command -v tput >/dev/null && tput setaf 1 && echo "tput red" && tput sgr0

  # 9. Color in an interactive session: drops you into bash to type your own
  #    color checks (see README).
  - name: test-color-interactive
    description: Interactive bash to test color by hand
    steps:
      - type: shell
        tty: true
        interactive: true
        command: 'echo "TERM=$TERM, colors=$(tput colors 2>/dev/null)"; exec bash --norc -i'
I am using
Copy code
atmos --chdir=/tmp/atmos-tty-test  test-lingering
to test. When I enter the shell, and hit
^C
it goes to the shell and does not kill Atmos.
I'm wondering if you would be able to give me an example test command like above that I can use to test iteratively.
(And yes you are on the correct sha)
m
my bad sorry
I had stashed the pending config changes in my client while doing somethign else over the weekend... so the tty: true, interactive: true config on the command from last weeks testing was gone and I didn't check before reporting above
with that restored, it's looking good.
šŸŽ‰ 1
I tested with all your test cases above, and they also all work as expected for me.
e
Excellent!
m
fwiw, my full command config attached - works beautifully now
I appreciate your time and quick turn around on this, thanks!
e
That looks super clean!
As someone really taking advantage of it, please let me know if there are other things we can do to improve it
āœ… 1