Skip to content

Open a Terminal

Browser terminals, SSH logins and port forwards into a running exec job.

Requirements:

1. Allow Terminals

Jobs with ssh = true accept terminal sessions from the browser and over SSH.

# flake.nix
apps.x86_64-linux.notebook = {
  type = "app";
  program = "${pkgs.bashInteractive}/bin/bash";
  passthru.gradient = { ssh = true; ports = [ 8888 ]; };
};
  • Programs of such jobs start on a terminal. bash programs wait for input and hold the job up until the shell exits.
  • A job with ssh = false provides the guest serial console as its only access.
  • Browser terminals, consoles, port forwarding and SSH logins need the openJobTerminal permission for the project. See Members and Roles.
  • triggerEvaluation alone doesn't open a terminal.
  • SSH logins into a job use the project role of the member with the SSH key. API keys have no effect on SSH logins.
  • Only API keys with openJobTerminal in their permission list can access terminals through the API.
  • New shells start as gradient in /work with the environment of the program.
  • Interactive programs obey maxSilent while Keep VM running is off. Input that the terminal echoes is output.

2. Use the Terminal Tab

The Terminal tab of the job page offers three sessions.

Session Job status Content
Console starting or running Serial console of the guest, logged in as gradient, starting with the last 64 KiB of output
Attach to program running, ssh = true, program not exited The terminal of the program
New shell running, ssh = true A new shell next to the program
  • The oldest viewer can type into the console. Later viewers see a read-only view.
  • Programs stay active past the close of an attached view.
  • Multi-node jobs add a Node picker. The log and every session follow the picked node.
  • Terminals and the console log in as gradient. The default guest image has no root login.

3. Log In over SSH

Login Target
<project>/<job-id> The job
<project>/<job-id>/<node> One node of a multi-node job, 0 for the master
<project>/<task> Node 0 of the newest running exec job of the task
ssh -p 2222 myproject/<job-id>@ci.example.com # (1)!
ssh -t -p 2222 myproject/<job-id>@ci.example.com shell # (2)!
ssh -p 2222 -N -L 8888:127.0.0.1:8888 myproject/<job-id>@ci.example.com # (3)!
  1. Attach to the terminal of the program.
  2. Open a new shell next to the program.
  3. Forward the local port 8888 to port 8888 inside the guest.

  4. Job pages show the ssh command and an ssh -N -L command per port once the job is running, ready to copy.

  5. SSH forwards reach only the ports in ports.
  6. gradient run -L <port> can forward ports without SSH keys. See Run a Program from the CLI for details.
  7. Logins accept no command except shell.
  8. Logins and forwards into a job before its start wait up to 30 minutes for the guest.
  9. Waiting logins print waiting for vm startup. Sessions close on a job end during the wait.
  10. Sessions close on a worker disconnect. Programs keep going.

4. Keep the VM Running

Click Keep VM running on the job page to hold the guest up after the program exit. The switch is available before the start and during the job.

Event Result
Program exit The job stays running, with the notice "Program exited with code N. The VM keeps running."
Let VM stop, or a second click on Keep VM running End as completed or failed by the recorded exit code
Abort End as aborted
Guest shutdown End by the recorded exit code
  • New shells, SSH logins and the console remain usable on a held guest.
  • Held guests pause maxSilent for the whole time of the hold. Release a guest to restart the maxSilent clock. The job timeout is active.
  • All nodes of a multi-node job follow the switch.

5. Shut Down the Guest

poweroff, shutdown, reboot, halt and systemctl poweroff run in every terminal and on the console. The user gradient can run them without a password.

  • Shutdowns during the program leave the job aborted, same as Abort. The job won't restart.
  • Shutdowns of a held guest close the job by the recorded exit code.

Verify Deployment

  • The Terminal tab of a running job opens the Console.
  • ssh -p 2222 <project>/<job-id>@<host> attaches to the program.

Next Steps