For the complete documentation index, see llms.txt. This page is also available as Markdown.

Track scripts

Add setup, pause, resume, and cleanup scripts to your tracks

Overview

Track scripts are powerful ways to configure sandboxes before and after a learner uses them. There are four types of track scripts:

  • Setup: Automate commands before a learner gets access to a track

  • Pause: Automate commands when learner pauses the track

  • Resume: Automate commands when learner resumes the track

  • Cleanup: Automate commands once a learner completes a track

A typical use case for a track setup script would be to deploy pods in a Kubernetes cluster, or to clone a git repository onto a machine. Track pause, resume, and cleanup scripts are not typically needed, but may be useful if you are managing resources outside of Instruqt sandboxes.

Every host in a sandbox has its own setup, pause, resume, and cleanup script. Additionally, learners can only start playing the track if all track setup scripts have been completed successfully with an exit code 0.

Track scripts

Track setup and cleanup scripts are added using the Web UI or the Instruqt CLI.

  1. Click the track you want to add track scripts to.

  2. In the Sandbox menu on the right-hand side of the Track Dashboard page, select Scripts.

  3. In the web editor, determine which host you want to add track scripts to. The hosts will be listed under the Tracks directory in the top-left corner of the editor.

  4. Add a script to the host's setup , pause , resume or cleanup file.

  5. Click Save.

  1. Track scripts are defined in the <track-name>/track_scripts directory and follow a <type>-<hostname> format. The four types of track scripts are setup, pause, resume, and cleanup. For example, to add a track setup script that runs on a host named webserver, you must create a file named setup-webserver in the track_scripts directory. Here is an example structure of a track directory:

    my-track/
        01-example-challenge/
        track.yml
        config.yml
        track_scripts/
            setup-webserver-vm
            pause-webserver-vm
            resume-webserver-vm
            cleanup-database-vm

Track setup scripts are executed in advanced as part of hot start pools.

Example setup script

The following is an example track setup script that installs a web server and pulls some code:

Example pause script

The following is an example track pause script that pauses an imaginary external resource via an API call:

Example resume script

The following is an example track resume script that resume an imaginary external resource via an API call:

Example cleanup script

The following is an example track cleanup script that deletes an imaginary resource via an API call:

Setup scripts

There are a couple of things specific to setup scripts that are good to know.

Wait for bootstrap

The track setup script for a host starts to run before Instruqt has finished bootstrapping the host. Use the following snippet to wait for the bootstrap to complete. This snippet ensures that files such as /root/.bashrc will not be overwritten if you change them.

Waiting for the bootstrap to complete is especially important if you plan to modify files like /root/.bashrc in the setup script. Generally speaking, it never hurts to add it in.

Exit on failure

Instruqt marks a sandbox as failed when the track setup script fails with exit code 1. And shows the learner an error if the track plays on-demand. If the sandbox runs hot started, Instruqt discards the sandbox before a learner sees the sandbox. To avoid putting learners in unfinished sandboxes, you should exit the track setup script when a failure happens. When using bash, it is good practice to start your track setup script with the following snippet. The set command ensures that your script will stop on all errors:

Last updated

Was this helpful?