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
  • Track setup scripts
  • Wait for bootstrap
  • Wait for service
  • Create a file
  • Download files
  • Start background process
  • Challenge check scripts
  • File exists
  • File doesn't exist
  • Directory exists
  • Directory doesn't exist
  • File contains certain text
  • Specific command is installed
  • Service is running

Was this helpful?

Edit on GitHub
  1. Sandboxes
  2. Lifecycle scripts

Example scripts

Example scripts that you can use in your lifecycle scripts.

These example scripts may use software that is not be available on every operating system.

Track setup scripts

Wait for bootstrap

Wait for the Instruqt bootstrap process to complete.

#!/bin/bash
set -euxo pipefail

until [ -f /opt/instruqt/bootstrap/host-bootstrap-completed ]; do
    echo "Waiting for instruqt bootstrap to complete"    sleep 1
done

The bootstrap process may overwrite user files like .bashrc. Wait is encouraged!

Wait for service

Wait for a specific web service in your setup script to finish booting.

while ! curl --fail --output /dev/null https://<hostname>:<port>/<path> 
do
    sleep 1
done

Create a file

Create a file using heredoc method.

cat > /file/to/create <<EOF
# Some configuration file
setting_one = true
another_setting = false
EOF

You can append to a file by using >> as opposed to >.

Download files

Download files to the local system.

git clone https://githost.com/repo <local_dir>
curl http://example.com/folder/big-file.iso -O <local_file>

Start background process

Start a process in the background so your script does not hang.

nohup ./myprogram > foo.out 2> foo.err < /dev/null & disown

Challenge check scripts

File exists

Check if a file exists:

#!/bin/bash
set -euxo pipefail

if [ -f /home/user/file.txt ]; then
    echo "The file at /home/user/file.txt exists"
fi

File doesn't exist

Check if a file doesn't exist (or is not a file):

#!/bin/bash
set -euxo pipefail

if [ ! -f /home/user/file.txt ]; then
    fail-message "No file was found at /home/user/file.txt"
fi

Directory exists

Check if a directory exists:

#!/bin/bash
set -euxo pipefail

if [ -d /root/folder ]; then
    echo "The directory at /root/folder exists"
fi

Directory doesn't exist

Use the following code in your life cycle script to check if a folder doesn't exist (or is not a directory)

#!/bin/bash
set -euxo pipefail

if [ ! -d /root/folder ]; then
    fail-message "The folder at /root/folder doesn't exists"
fi

File contains certain text

Check if a file contains certain text.

#!/bin/bash
set -euxo pipefail

if ! grep "text to find" /path/to/file; then
    fail-message "The file doesn't contain the required text"
fi

Specific command is installed

Check that a specific command is executable with the -x flag.

#!/bin/bash
set -euxo pipefail

if ! [[ -x /usr/local/bin/command ]]; then
  fail-message "Oops, command was not found or is not executable."
fi

Service is running

Check if a service is running.

#!/bin/bash
if pgrep -x SERVICE >/dev/null; then
    echo "The X service is running"
fi

Replace SERVICE with a service name running on that system.

PreviousChallenge scriptsNextHelper scripts

Last updated 1 year ago

Was this helpful?

🏖️