Syntax
Global Options
Arguments:
RUNNABLE- Python script file or directory to execute (required unless a process-management flag such as--kill,--kill-all,--reattach,--continue, or--consoleis used)ARGS- Additional arguments passed to the script
--kill/--kill-all: SIGINT, SIGQUIT, SIGABRT, SIGKILL, SIGUSR1, SIGUSR2, SIGTERM, SIGSTOP
Basic Usage
Environment Variables
Setting Variables
Auto-Injected Variables
The following environment variables are automatically available inside your script:File Downloads
Each run has its own output folder on the box. Write the files your script makes tolager.output_dir():
--download to get all of them back:
lager.output_dir(), with any subfolders, and the run record. The CLI then
compares each file with the hash in the record:
--download. Without --download, the CLI does not save anything on your
computer. Outside lager python, lager.output_dir() returns a lager-output
folder in the current directory, so the script still runs on your computer.
Detached Mode
Run scripts in the background without waiting for output:- The command returns as soon as the box accepts the job. It returns before the
script starts, and before any setup that the script needs (unpacking a module
directory, installing its
requirements.txt) - No stdout/stderr is streamed back
- The script continues running on the box
- Use
--reattachto see its output,--killto stop it later
requirements.txt that will not install, say.
You see that failure through the job, not at the prompt. --reattach shows the
failure and exits non-zero:
Box 'my-lager-box' is held for the detached run and released when it ends.
An older box keeps the lock after the job ends. The CLI then prints
release with: lager boxes unlock --box my-lager-box. See
locking.
Killing Running Scripts
--kill takes the process ID that the detached launch printed.
Port Forwarding
Forward network ports from the box to your local machine:SRC_PORT[:DST_PORT][/PROTOCOL]
Timeout
Limit script execution time:0, the default, means no limit.- An attached run is capped at 300 seconds. A larger value runs for 300 seconds, and the box writes the cap to its log.
- A detached run has no cap. The box applies the value only when you give one.
- First, SIGTERM is sent. The CLI prints
Script terminated due to timeout.and exits with code 124 - If the script does not exit within 5 seconds, SIGKILL is sent. The CLI prints
Script forcibly killed due to timeout.and exits with code 137
Structured Output
Scripts running on the box can send structured data back to the CLI using thelager.core.output() function. This uses a dedicated output channel (file descriptor 3) separate from stdout/stderr.
Box-Side API
Structured output is printed to the CLI console as it arrives. Standard stdout and stderr are streamed separately in real time.
Module Includes
If your script depends on local modules, configure includes in a.lager file in your project. The file is JSON:
.lager file. The CLI starts at the directory of the script, and searches up the directory tree for a .lager file. It then zips the script along with all include directories before uploading to the box.
test.py:
Additional Files
Upload extra files alongside your script:Exit Codes
Run Record
The box writes a run record for each run. The record is a JSON file. It shows what ran, on which box, in which state, and what came out:- The SHA-256 hash of each file that the box received
- The box state when the run started: the Lager version, the OS, the net configuration, and the serial number of each instrument
- The start time, the end time, and the exit code
- Why the run ended: it exited, it timed out, it was cancelled, or the client disconnected
- The SHA-256 hash of the output and of each file in the run’s output folder
- On the box, for every run. The box keeps the records of its most recent 500 runs.
- In the box’s outbox, if a collector manages the box. A collector is a service that takes each record from the box and keeps it somewhere else. These records stay in the outbox until the collector takes them.
- On your computer, only with
--download. The CLI writes the record as<process-id>.lager-run.jsonin the run’s folder, next to the downloaded files (see File Downloads). The CLI compares the output and the downloaded files with the hashes in the record. If they are different, the CLI shows a warning.
docs/reference/run-record.md in the Lager
repository.
Box Lock
lager python takes the box lock when it runs a script. Another user then cannot
drive the same box at the same time. See locking.
- An attached run holds the lock while the script runs. The command releases it when it exits.
- If another user holds the lock, the command fails at once on your computer. In CI, it waits for the lock.
--kill,--kill-all,--reattach,--continue, and--consoledo not take the lock.- Set
LAGER_AUTO_LOCK_DISABLE=1to run without the lock.
Examples
Hardware Test Script Example
Notes
- Use
--envfor script-specific configuration values - Use
--passenvfor secrets/tokens from your current shell --downloadretrieves files only after script completion (not during), and only the files inlager.output_dir()- Port forwarding syntax:
SRC_PORT[:DST_PORT][/PROTOCOL] - Output is streamed in real time via a multiplexed HTTP protocol with keepalive (20-second interval)
Installing Python packages
Scripts run inside the Lager Python container on the box. To install the packages that your scripts depend on, use the declarativelager box-config pip
commands. Those commands record the packages in the box config and rebuild the
container. The packages then persist across lager python runs and box updates.
The standalone
lager pip command was removed and folded into
lager box-config pip.
