Open a Terminal¶
Browser terminals, SSH logins and port forwards into a running exec job.
Requirements:
- An exec worker with
exec.allow.ssh = true, see Set Up an Exec Worker - The SSH server and a key for SSH logins, see Build over SSH
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.
bashprograms wait for input and hold the job up until the shell exits. - A job with
ssh = falseprovides the guest serial console as its only access. - Browser terminals, consoles, port forwarding and SSH logins need the
openJobTerminalpermission for the project. See Members and Roles. triggerEvaluationalone 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
openJobTerminalin their permission list can access terminals through the API. - New shells start as
gradientin/workwith the environment of the program. - Interactive programs obey
maxSilentwhile 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)!
- Attach to the terminal of the program.
- Open a new shell next to the program.
-
Forward the local port 8888 to port 8888 inside the guest.
-
Job pages show the
sshcommand and anssh -N -Lcommand per port once the job isrunning, ready to copy. - SSH forwards reach only the ports in
ports. gradient run -L <port>can forward ports without SSH keys. See Run a Program from the CLI for details.- Logins accept no command except
shell. - Logins and forwards into a job before its start wait up to 30 minutes for the guest.
- Waiting logins print
waiting for vm startup. Sessions close on a job end during the wait. - 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
maxSilentfor the whole time of the hold. Release a guest to restart the maxSilent clock. The jobtimeoutis 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¶
- Build over SSH: SSH server and key setup
- Members and Roles:
openJobTerminalpermission - Spread a Job over Workers: node logins