raft / docs
Guides

Background jobs

Raft runs detached background commands under the guest systemd init system using transient service units.

Target workspace handle

Commands in this guide target a running workspace. Select one from raft list (see First working box):

CONTROLLER: Select running workspace
raft list
box="lab:rf-a1b2c3d4e5f60718"  # Replace with your actual workspace handle

Launching detached commands

Start a background command by passing --detach to raft exec, delimiting the payload with --:

CONTROLLER: Start a detached background job
job=$(raft exec "$box" --detach -- bash -lc '
echo "Task started at $(date)"
sleep 60
echo "Task finished at $(date)"
')
echo "Started background job: $job"

The command returns a 32-hex systemd unit name prefixed with rfcmd- (such as rfcmd-a1b2c3d4e5f60718293a4b5c6d7e8f90).

Checking job status

Use raft status to query guest systemd unit properties:

CONTROLLER: Inspect background job state
raft status "$box" "$job"

Active jobs report running substate:

ActiveState=active
SubState=running
ExecMainStatus=0

Because Raft runs detached commands with RemainAfterExit=yes, completed jobs retain their exit record:

ActiveState=active
SubState=exited
ExecMainStatus=0

Exit status vs CLI return code

ExecMainStatus reports the command payload exit code inside the container. The raft status command returns exit code 0 when the query succeeds. It queries unit state and does not report process PIDs or start timestamps.

Viewing job logs

Retrieve output recorded in the guest systemd journal:

CONTROLLER: Retrieve job log output
raft logs "$box" "$job"

The command runs journalctl --no-pager -o cat -u <job> inside the container. It prints recorded logs without a pager or stream follow mode.

Cancelling jobs

Terminate a running detached command:

CONTROLLER: Terminate background job
raft cancel "$box" "$job"

raft cancel executes systemctl stop <job>, terminating processes in the job's systemd control group.

Extending workspace lifetime

No process checkpointing

Stopping a workspace with raft stop or allowing its TTL to expire terminates all running background jobs. Raft does not checkpoint running process memory.

Extend the workspace lifetime before it expires:

CONTROLLER: Reset workspace expiration
raft extend "$box" --ttl 1800

raft extend resets the container expiration deadline to now + TTL seconds using the host clock. It does not add time to the existing deadline.

On this page