Skip to content

You start a job in your VM and disconnect. The job keeps running, and you read its log and exit code later.

  • A VM. Create one from your terminal and keep its id.
  • An organization key.
  • A command to run in the VM. This guide runs tests in /home/user/app. Use your project’s directory and test command.

Set these once in your terminal. Step 1 prints the job number, so set JOB to it.

Terminal window
export SI_API_KEY=<your-organization-key>
VM=<your-vm-id>
JOB=3

Send the script as the body of a POST to /usr/bin/job. With arg=-q the reply is the job number alone. The reply also carries a Location header that names the job’s log.

Terminal window
curl -sS -H "Authorization: Bearer $SI_API_KEY" --data-binary 'cd /home/user/app && npm test' "https://$VM.slashinfra.dev/usr/bin/job?arg=-q"
Output
3

Close your terminal or let your script end. The job runs after the request ends, and its files and log stay in the VM. A busy job keeps the VM awake, so it runs until it ends.

The log is at /var/log/jobs/<number>.log. Read it at any time, while the job runs or after it ends.

Terminal window
curl -sS -H "Authorization: Bearer $SI_API_KEY" "https://$VM.slashinfra.dev/var/log/jobs/$JOB.log"
Output
...
Tests: 42 passed, 0 failed

A POST to /usr/bin/job with arg=wait and the job number waits for the job to end. The X-Exit-Code header carries the job’s exit code.

Terminal window
curl -sS -D - -o /dev/null -X POST -H "Authorization: Bearer $SI_API_KEY" "https://$VM.slashinfra.dev/usr/bin/job?arg=wait&arg=$JOB"
Output
HTTP/2 200
X-Exit-Code: 0

A wait can end before the job does. When the reply has X-Timeout: 1, the job still runs. Send the same request again.

You should now see the job’s log and an X-Exit-Code that matches the result in the log. 0 means the job passed.

Symptom Cause Fix
X-Exit-Code: 137 Something killed the job before it ended. Read the log to find the last line the job printed.
X-Timeout: 1 The wait ended before the job did. Send the wait again.

Scroll horizontally to see all columns.

Terminal window
curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE -H "Authorization: Bearer $SI_API_KEY" "https://api.slashinfra.com/svms/$VM"
Output
204
  • Sleep and wake: a busy job keeps the VM awake, and a sleep on disk ends its process.
  • Services: a program the VM starts again after it wakes, for work that must keep running.
  • Limits: the command and output limits that a job’s program runs under.
  • Commands and jobs: every command, terminal and job operation, with its options and limits.