Example scripts
Example scripts that you can use in your lifecycle scripts.
Last updated
Was this helpful?
Example scripts that you can use in your lifecycle scripts.
Last updated
Was this helpful?
Was this helpful?
These example scripts may use software that is not be available on every operating system.
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
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 using heredoc method.
cat > /file/to/create <<EOF
# Some configuration file
setting_one = true
another_setting = false
EOF
Download files to the local system.
git clone https://githost.com/repo <local_dir>
Start a process in the background so your script does not hang.
nohup ./myprogram > foo.out 2> foo.err < /dev/null & disown
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
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
Check if a directory exists:
#!/bin/bash
set -euxo pipefail
if [ -d /root/folder ]; then
echo "The directory at /root/folder exists"
fi
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
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
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
Check if a service is running.
#!/bin/bash
if pgrep -x SERVICE >/dev/null; then
echo "The X service is running"
fi