Skip to Content
ReferenceActionsSLURM

Slurm Action

The Slurm action submits jobs to Slurm , waits for them to end and reads what they printed, cancels them, and reads the state of the partitions and the nodes of the cluster. It runs the commands of Slurm, sbatch, squeue, sacct, scancel and scontrol, on a login node over SSH, or on the host Probe runs on, and reads what they print with --json. Where the cluster serves slurmrestd , it asks that instead, with the same result.

It is an external action, published in mozership/probe-slurm . Probe downloads it the first time a workflow uses it, and runs the executable whose SHA-256 the action.yml at the pinned commit names. It is tested with Probe v1.40.0 and later. The examples write <commit SHA> for the commit to pin: probe guide slurm prints the uses line of the latest release, and so do the notes of each release.

Basic Syntax

A workflow pins the action by a full commit SHA, and gives it a name once, under actions:

name: Canary job actions: slurm: github.com/mozership/probe-slurm@<commit SHA> jobs: - name: canary defaults: slurm: host: login.hpc.example.com user: probe key_file: ~/.ssh/id_ed25519 steps: - name: The partition is up, with a node to spare uses: slurm with: partitions: debug test: res.partitions[0].state == "UP" && res.partitions[0].idle > 0 - name: Submit a job id: submit uses: slurm with: submit: partition: debug time: 5m script: | #!/bin/bash srun hostname test: res.job_id > 0 outputs: job_id: res.job_id - name: It ends well, soon enough uses: slurm with: job: "{{outputs.submit.job_id}}" wait: 30m output: true test: | res.state == "COMPLETED" && res.exit_code == 0 && res.wait_sec < 600 && res.stdout != ""

A job is submitted by one step and waited for by another, so that a retry of the step that waits never submits the job again.

Parameters

A step does one thing, by one of these keys of with:

KeyWhat it doesValue
submitSubmits a job with sbatchThe job
jobReads the state of a job, waiting for it to end with waitThe ID of the job
jobsLists the jobs in the queueWhat the jobs have, or nothing for every job
cancelCancels a job with scancelThe ID of the job
partitionsReads the state of a partition, and counts its nodes by their stateThe name of a partition, or nothing for every one
nodesReads the state of nodesNodes, as c1 or c[1-4], or nothing for every one

The others say how Slurm is asked: by its commands, on a login node or on this host, or by slurmrestd:

ParameterTypeRequiredDefaultDescription
hostStringNo-The login node to run the commands on, over SSH. Without it, they run on the host Probe runs on
portIntegerNo22The port of SSH
userStringNoUSERThe user to log in as. With endpoint, the user to act as, for a token of SlurmUser or root
key_fileStringNoSee Logging inThe private key to log in with. ~/ is the home directory
key_passphraseStringNo-The passphrase of key_file
known_hostsStringNo~/.ssh/known_hosts and /etc/ssh/ssh_known_hostsThe file the host key of the login node is checked against
bin_dirStringNoThe PATHThe directory of the commands of Slurm, as /opt/slurm/bin, where the PATH of a command run over SSH does not find them
endpointStringNo-The URL of slurmrestd, as https://slurm.hpc.example.com:6820, to ask it rather than run the commands
tokenStringNoSLURM_JWTThe JSON Web Token slurmrestd takes, as scontrol token prints it
timeoutDurationNo30s, and as long as wait besidesTime limit for the whole step, as 10s or a number of seconds

A key of with that is not one of these fails the step before anything is run. Its action.yml declares them as params, and the fields of the result as res, so probe check reports such a key, and a field of res the action does not return, with its line.

The job’s defaults, keyed by the name the workflow gave the action, are merged key by key, so a job can keep its login node, and what its jobs are submitted with, out of each step:

defaults: slurm: host: login.hpc.example.com submit: partition: debug account: lab

A submit without script or file, as those defaults are, is left out of a step that does something else.

Logging in

The action logs in with key_file when it is given. Without it, it tries the keys of the agent at SSH_AUTH_SOCK, then those of ~/.ssh/id_ed25519, ~/.ssh/id_ecdsa and ~/.ssh/id_rsa that have no passphrase. It does not log in with a password, nor with keyboard-interactive authentication, such as the one-time passwords some sites ask for.

The host key is always checked, against known_hosts or the files OpenSSH keeps, so a login node the files do not know fails the step. Add it first, as ssh-keyscan login.hpc.example.com >> ~/.ssh/known_hosts does once you have checked what it prints.

Each command runs as the line of a non-interactive shell of the user, as ssh user@host 'squeue --json' would. Where the commands of Slurm are only found once a login shell has set the PATH, give their directory as bin_dir.

key_passphrase is not shown in the result or in the action’s own log. Declaring the variable it is read from under secrets hides its value anywhere else it could appear.

By slurmrestd

With endpoint, the action sends each request to slurmrestd, with the token in X-SLURM-USER-TOKEN, and runs no command. The token is that of the user the jobs run as, as scontrol token lifespan=86400 prints it on the login node, and is read from SLURM_JWT when token is not given. SLURM_JWT= before it, as scontrol token prints it, is taken off.

defaults: slurm: endpoint: https://slurm.hpc.example.com:6820 submit: chdir: /home/probe

The action speaks the versions v0.0.39 to v0.0.42 of the API, of Slurm 23.02 to 24.11, and takes the newest the server serves, which req.api_version tells. The results are those of the commands, but for what slurmrestd does otherwise than sbatch:

  • submit requires chdir, as the job has no directory of the shell it was submitted from, and runs with only PATH=/usr/local/bin:/usr/bin:/bin in its environment, besides what Slurm sets.
  • slurmrestd reads none of the #SBATCH lines of a script, so give the options in with.submit. It takes none of the options of sbatch, so options fails the step, and res.cluster is always empty.
  • job cannot read the output of a job, which is a file on the cluster, so output fails the step.
  • A job slurmctld has forgotten is read from the accounting, where slurmrestd serves it.

The token is not shown in the result or in the action’s own log. The action follows no redirect, so the token goes to no host but that of endpoint.

Submit

submit sends the script to sbatch --parsable on its standard input, with the options below. It has script or file, and not both.

ParameterTypeDefaultsbatch optionDescription
scriptString--The batch script, starting with #!
fileString--Path to the batch script on the host Probe runs on, relative to the working directory. It is read there and sent, as script is
nameStringprobe--job-nameThe name of the job
partitionStringThe cluster’s default--partition
accountString---account
qosString---qos
timeString or IntegerThe partition’s--timeThe time limit: a duration as 1h30m, rounded up to whole minutes, a time as sbatch takes it as 1-12:00:00, or a number of minutes, as sbatch reads one
nodesInteger or String---nodesAs 2, or 1-4
ntasksInteger---ntasks
cpus_per_taskInteger---cpus-per-task
memString---memAs 4G
gresString---gresAs gpu:1
chdirStringThe home directory; required with endpoint--chdirThe working directory of the job, on the cluster
outputStringslurm-%j.out--outputWhere the job writes its standard output, on the cluster
errorStringWith output--errorWhere the job writes its standard error, on the cluster
optionsArray--Other options of sbatch, each as --exclusive or --constraint=a100. Not with endpoint
keepBooleanfalse-Keeps the job out of the cleanup of the run

Options in the script, as #SBATCH --partition=long, are taken too, and those given here win over them, as sbatch takes options on its command line. slurmrestd takes only those given here.

Response Object

PropertyTypeDescription
res.job_idIntegerThe ID of the job, or 0 when sbatch refused it
res.clusterStringThe cluster the job went to, when sbatch names one, or empty
res.errorStringWhat sbatch said when it refused the job, as sbatch: error: invalid partition specified: nope, or empty
reqObjectWhat was done: operation, host, port, user, bin_dir, the script or file, keep, and the command that was run, or the endpoint and the api_version it was asked by. It never has key_passphrase or token
rtDurationTime the step took
statusInteger0 when the job was submitted; 1 otherwise

sbatch refusing the job is a result, so a test can assert on a partition or an account that should be closed. Only a command that cannot be run, such as on a login node that cannot be reached, fails the step as an error.

Job

job reads the state of the job, from squeue, or from sacct once slurmctld has forgotten it. A job neither knows fails the step.

ParameterTypeDefaultDescription
waitDuration0sHow long to wait for the job to end. The step returns as soon as it has ended, and otherwise returns it as it is once wait is over
pollDuration10sHow often the job is looked at while the step waits, 1s or longer
outputBooleanfalseReads the standard output of the job, once it has started, into res.stdout

The output is read on the host the commands run on, from the path squeue or sacct tells, so it must be on a file system the login node shares with the compute nodes, as the home directory usually is.

Response Object

PropertyTypeDescription
res.job_idIntegerThe ID of the job
res.nameStringThe name of the job
res.userStringThe user it runs as
res.accountStringIts account
res.partitionStringIts partition
res.stateStringIts state, as PENDING, RUNNING, COMPLETED, FAILED, CANCELLED, TIMEOUT, OUT_OF_MEMORY or NODE_FAIL
res.reasonStringWhy it waits, or why it ended, as Priority, Resources or PartitionDown, or empty
res.nodesStringThe nodes it runs on, as c[1-2], or empty
res.exit_codeIntegerThe exit code of its script
res.signalIntegerThe signal it was ended by, or 0
res.submit_timeStringWhen it was submitted, as 2026-11-27T01:02:03Z
res.start_timeStringWhen it started, or empty until it does
res.end_timeStringWhen it ended, or empty until it does
res.wait_secIntegerSeconds it waited in the queue, or has waited so far
res.elapsed_secIntegerSeconds it ran, or has run so far
res.doneBooleanWhether it has ended
res.stdout_pathStringWhere it writes its standard output, on the cluster
res.stdoutStringWith output, the first 1 MiB of its standard output; empty until it starts
res.stdout_truncatedBooleanWith output, whether the output is larger than 1 MiB
reqObjectoperation, the connection, job_id, wait, output and the command
rtDurationTime the step took
statusInteger0 when the job has completed with the exit code 0; 1 otherwise, while it waits or runs too

Jobs

jobs lists the jobs squeue lists, by what they have. Each key narrows the list, and none lists every job in the queue.

ParameterTypeDescription
userStringThe user they run as
partitionStringTheir partition
stateStringTheir state, as pending or RUNNING. Without it, squeue lists those pending and running
nameStringTheir name
accountStringTheir account

res.jobs has each job, with the fields job returns but stdout, and res.count how many there are.

Cancel

cancel cancels the job with scancel. The job is looked up first, as scancel exits with 0 for a job it does not know, or one that has ended: a job neither squeue nor sacct knows fails the step, and one that has ended is left as it is.

PropertyTypeDescription
res.job_idIntegerThe ID of the job
res.stateStringThe state of the job before it was cancelled
res.cancelledBooleanWhether it was cancelled; false for one that had ended
res.errorStringWhat scancel said when it refused, as for the job of another user, or empty
statusInteger0 unless scancel refused

Partitions

partitions reads the partition, or every partition, from scontrol show partition, and counts its nodes by their state, from scontrol show node. res.partitions has each, and res.count how many there are. A partition the cluster does not have fails the step.

PropertyTypeDescription
nameStringThe name of the partition
stateStringIts state, as UP, DOWN, DRAIN or INACTIVE
total_nodesIntegerHow many nodes it has
idle, mixed, allocatedIntegerHow many of them are idle, partly allocated, and wholly allocated
downIntegerHow many are down, drained or not
drainedIntegerHow many are drained, or being drained, and up
otherIntegerHow many are in any other state, as FUTURE or UNKNOWN

Nodes

nodes reads the nodes from scontrol show node. res.nodes has each, and res.count how many there are; nodes the cluster does not have are not among them.

PropertyTypeDescription
nameStringThe name of the node
stateStringIts state, as IDLE, MIXED, ALLOCATED or DOWN
flagsArrayThe flags of its state, as DRAIN or NOT_RESPONDING
partitionsArrayThe partitions it is in
reasonStringWhy it is down or drained, or empty
cpusIntegerIts CPUs
alloc_cpusIntegerHow many of them are allocated

Cleanup

Once the run is over, whether it passed, failed or was interrupted, Probe calls the action, as Cleaning Up After a Run tells, to cancel the jobs its steps submitted, those that have ended aside, so a run that stops waiting leaves no job in the queue. A job submitted with keep: true is left.

The jobs are noted, with where they were submitted, in a file under the temporary directory, which the cleanup removes. The passphrase of a key is not noted, so the jobs submitted with key_passphrase are cancelled by logging in with the agent or the default keys. Nor is the token, so the jobs submitted by slurmrestd are cancelled with the token in SLURM_JWT, and are left when it gives none. A cleanup that cannot log in is told as a warning, which names the jobs left.

Under a Guard

The action keeps to the guard of the run, and its action.yml declares guard: [read-only, allow-host], so Probe runs it under --read-only and --allow-host without --allow-action.

  • Under --read-only, job, jobs, partitions and nodes are run, and submit and cancel are refused before anything is run.
  • Under --allow-host, the commands run only on a host the run allows, as login.hpc.example.com or login.hpc.example.com:2222, and slurmrestd is asked only at an endpoint whose host the run allows, at the port of its scheme when the URL has none. Without either, the commands reach whatever slurmctld the host Probe runs on is set up for, which the guard cannot check, so such a step is refused.

A refused step fails with the kind refused. See Guard.

Slurm Versions

The action reads what the commands print with --json, and what slurmrestd answers, which differ between the versions of Slurm, and is tested against what Slurm 23.02 to 24.11 print. The end-to-end tests  run it against Slurm 24.11 in a container, over SSH and by slurmrestd.

Job arrays are not told apart: job and cancel take the ID of a job, and jobs lists each task of an array as a job of its own.

See Also

  • External Actions - How Probe resolves and checks an external action
  • SSH - Commands on a remote server over SSH
  • Container - Containers started for a run, and removed after it
Updated at