Instruqt Docs
  • 🚩Getting started
    • Overview
    • Setting up
      • Study Room
    • Quickstart
  • 🛤️Tracks
    • Manage tracks
      • Create tracks
      • Edit locally
      • Test tracks
      • Track logs
      • Track time limits
      • Track feedback
      • Developer workflow
      • Track tags
      • Track authors
      • Delete tracks
      • Custom layouts
      • Version control
      • Loading experience
    • Challenges
      • Create challenges
      • Challenge tabs
      • Challenge order
      • Skip challenges
      • Add quizzes
      • Assignment display
      • Assignment editor
    • Share tracks
      • Live Events
        • Instructor tools
      • Track invites
      • Embed tracks
      • Landing pages
  • 🏖️Sandboxes
    • Overview
    • Sandbox hosts
      • Add hosts
      • Custom VM images
      • Custom container images
      • Public images
      • Windows VMs
      • Website service
      • SSL certificates
    • Cloud accounts
      • Securing your cloud accounts
      • Cloud Client
      • AWS accounts
        • AWS Environment Variables
        • AWS Managed Policies
        • AWS IAM Policies
        • AWS SCP Policies
      • Azure subscriptions
        • Azure Environment Variables
        • Azure Roles
        • Azure Resource Providers
      • GCP projects
        • GCP Environment Variables
        • GCP IAM Permissions
    • Lifecycle scripts
      • Scripting overview
      • Track scripts
      • Challenge scripts
      • Example scripts
      • Helper scripts
    • UI Checks
    • Global Sandbox Settings
      • Hot start
      • Sandbox presets
      • Custom resources
      • Cloud services and regions
        • Allowed services and regions
    • Secrets and variables
      • Runtime variables
      • Runtime parameters
      • Secrets
  • ⚙️Settings
    • Integrations
      • Salesforce (Beta)
      • HubSpot (Beta)
      • HubSpot (Using zapier)
      • LTI
      • Version control
        • GitHub
    • Authentication
      • SSO
      • API keys
    • Platform
      • API
      • Webhooks
      • Track limits
  • 💡Reference
    • Feature overview
    • Instruqt CLI
      • Commands
      • Configuration files
      • Assets
    • Instruqt platform
      • Networking
      • Host machine types
      • Quotas and limits
      • Roles and permissions
      • Network access
      • Requirements
  • 🛟Resources
    • Content design tips
    • Advanced use cases
    • Templates
    • FAQ
      • Running Windows Client Hosts on Instruqt
      • Using Cleanup Scripts in SaaS and Cloud Environments
      • Instruqt Regional Configurations and Restrictions
      • Troubleshooting Instruqt CLI Authentication Issues
      • Copy a Track from One Organization to Another via CLI
      • Network Configuration: IP and MAC Address Control
      • Container Troubleshooting in Instruqt
Powered by GitBook
On this page
  • Overview
  • Track scripts
  • Setup scripts
  • Wait for bootstrap
  • Exit on failure

Was this helpful?

Edit on GitHub
  1. Sandboxes
  2. Lifecycle scripts

Track scripts

Add setup and cleanup scripts to your tracks

PreviousScripting overviewNextChallenge scripts

Last updated 2 months ago

Was this helpful?

Overview

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

  • Setup: Automate commands before a learner gets access to a 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 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 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.

The longer a track setup script runs, the longer your learners must wait. Reduce wait times by incorporating as much as you can into

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 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 two types of track scripts are setup 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
            cleanup-database-vm

Track setup scripts are executed in advanced as part of

Example setup script

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

#!/bin/bash
set -euxo pipefail

apt update
apt install nginx -y

git clone https://github.com/my-web-repo

Example cleanup script

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

#!/bin/bash
set -euxo pipefail

curl -X DELETE -s "https://example.com/api/resource/1234"

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.

while [ ! -f /opt/instruqt/bootstrap/host-bootstrap-completed ]
do
    echo "Waiting for Instruqt to finish booting the virtual machine"
    sleep 1
done

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:

#!/bin/bash 
set -euxo pipefail

🏖️
custom VM images.
hot start pools.