You start a job in your VM and disconnect. The job keeps running, and you read its log and exit code later.
Before you start
Section titled “Before you start”- 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.
export SI_API_KEY=<your-organization-key>VM=<your-vm-id>JOB=31. Start a job
Section titled “1. Start a job”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.
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"3import osimport requests
res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, params={"arg": "-q"}, data=b"cd /home/user/app && npm test",)print(res.text)const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job?arg=-q`, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` }, body: 'cd /home/user/app && npm test',})console.log(await res.text())2. Disconnect
Section titled “2. Disconnect”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.
3. Read the log
Section titled “3. Read the log”The log is at /var/log/jobs/<number>.log. Read it at any time, while the job runs or after it ends.
curl -sS -H "Authorization: Bearer $SI_API_KEY" "https://$VM.slashinfra.dev/var/log/jobs/$JOB.log"...Tests: 42 passed, 0 failedimport osimport requests
res = requests.get( f"https://{os.environ['VM']}.slashinfra.dev/var/log/jobs/{os.environ['JOB']}.log", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},)print(res.text)const res = await fetch(`https://${process.env.VM!}.slashinfra.dev/var/log/jobs/${process.env.JOB!}.log`, { headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },})console.log(await res.text())4. Read the exit code
Section titled “4. Read the exit code”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.
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"HTTP/2 200X-Exit-Code: 0import osimport requests
res = requests.post( f"https://{os.environ['VM']}.slashinfra.dev/usr/bin/job", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}, params={"arg": ["wait", os.environ["JOB"]]},)print(res.headers["X-Exit-Code"])const url = new URL(`https://${process.env.VM!}.slashinfra.dev/usr/bin/job`)url.searchParams.append('arg', 'wait')url.searchParams.append('arg', process.env.JOB!)
const res = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },})console.log(res.headers.get('X-Exit-Code'))A wait can end before the job does. When the reply has X-Timeout: 1, the job still runs. Send the same request again.
Check it works
Section titled “Check it works”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.
If it doesn’t work
Section titled “If it doesn’t work”| 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.
Clean up
Section titled “Clean up”curl -sS -o /dev/null -w "%{http_code}\n" -X DELETE -H "Authorization: Bearer $SI_API_KEY" "https://api.slashinfra.com/svms/$VM"API reference: Control API operation
204import osimport requests
res = requests.delete( f"https://api.slashinfra.com/svms/{os.environ['VM']}", headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},)print(res.status_code)const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}`, { method: 'DELETE', headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },})console.log(res.status)- 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.