What is a Configuration Script?
A configuration script in Arcus is a shell script or Windows PowerShell script that can perform automated actions as part of the deployment process.
In Arcus, there are two types of configuration scripts: master and host.
Master configuration scripts are attached to the master node of your scenario, whereas host configuration scripts can be attached to each host in your scenario (including the master node).
What is a Teardown Script?
A teardown script in Arcus functions the same way as a configuration script but as part of the deployment run release process instead of the deployment process.
As with configuration scripts, there are two types of teardown scripts: master and host.
Master teardown scripts are attached to the master node of your scenario, and host teardown scripts can be attached to each host in your scenario (including the master node).
How do I set up Configuration and Teardown Scripts?
To set your configuration and teardown scripts, either create a new Arcus scenario, or modify an existing scenario.
At the Configuration step, you will be presented with the following screen:
Click the green Set button on any of the hosts to open the configuration and teardown script window.
From here, you can set the name of the script in the top field, as well as enter the content of your script in the bottom field.
Once you’ve completed your desired scripts and saved the changes, complete the remainder of the scenario build process as described here.
Once the scenario is complete, you can review the build order and view any configuration or teardown scripts by clicking on the desired scenario. View your configuration scripts under “Build Sequence,” and any teardown scripts under “Teardown Sequence” (see below).
What can I do with these Scripts?
Configuration and teardown scripts are often used as notifications, verifications of success/failure, and triggers for workflows or third-party tools and applications outside of the Arcus host currently being built or released.
Below is an example bash
configuration script that does a simple status check on the machine during the deployment process:
#!/bin/bash
# Set log commands
logTag=$(basename -- "$0")
logInfo="logger -i -s -p local3.info -t ${logTag} [INFO] "
logWarn="logger -i -s -p local3.warning -t ${logTag} [WARNING] "
logErr="logger -i -s -p local3.err -t ${logTag} [ERROR] "
# Get the current timestamp and append to logfile name
TIMESTAMP=$(date "+%Y-%m-%d-%H%M")
${logInfo} "Sourcing /etc/bashrc to get the environment ..."
source /etc/bashrc
######################### GLOBAL VARIABLES #########################
# Array to maintain exit codes of all commands
resultSet=();
####################### END GLOBAL VARIABLES #######################
# Parameters:
# 1 - Command to execute
# Returns:
# Exit code of the command that was executed
function run_and_check_status() {
local command="$@"
${command}
local status=$?
if [ ${status} -ne 0 ] ; then
${logErr} "Error executing: ${command}, exited with code: ${status}"
else
${logInfo} "${command} executed successfully and exited with code: ${status}"
fi
resultSet+=("${status}")
return ${status}
}
# Main remove function
function main() {
${logInfo} "Beginning check of file system on all hosts..."
${logInfo} "Timestamp: ${TIMESTAMP}"
################# display free disk space ###################
${logInfo} "cd /var/log"
run_and_check_status cd /var/log
${logInfo} "df -h"
run_and_check_status df -h
################# display disk utilization ###################
${logInfo} "du -sh"
run_and_check_status du -sh
# Check the results of commands from this script, return error if an error is found
for resultCheck in "${resultSet[@]}" ; do
if [ ${resultCheck} -ne 0 ] ; then
${logErr} "Non-zero exit code found: ${resultCheck}"
return 1
fi
done
${logInfo} "Completed asset check successfully!"
return 0
}
main
result=$?
${logInfo} "Exiting with code ${result} ..."
exit ${result}
When are Configuration Scripts run?
For any enabled configuration scripts, these are run after clicking Launch on the chosen deployment.
After your deployment run has completed the “building systems” phase, and after all asset installs are completed, your deployment run will begin the “building scenario” phase.
In the building scenario phase, the CONS3RT Agent will download any master configuration scripts and run them. After the master configuration script is complete, the CONS3RT Agent will download any host configuration scripts and run them in parallel. Even if your systems have a specific build order, host configuration scripts are run in parallel and will have no specific order defined.
Once the scripts have been run, the CONS3RT Agent will continue with the remainder of the Arcus deployment run launch process.
This order of operations for configuration scripts can be reviewed visually by clicking on the scenario in question. The overview screen lists the sequence that configuration scripts and other actions will follow once deployed.
When are Teardown Scripts run?
Enabled teardown scripts are run after clicking Release on the chosen active run.
The CONS3RT Agent will then download any host teardown scripts and run them. Like configuration scripts, host teardown scripts are run in parallel.
After the host teardown script is complete, the CONS3RT Agent will download master teardown scripts.
This order of operations for teardown scripts can be reviewed visually by clicking on the scenario in question. The overview screen lists the sequence that teardown scripts and other actions will follow once released.
Tips for using Configuration & Teardown Scripts
On Linux-based systems, the shell in which the script will run may vary between operating systems. We recommend always including a shebang #!/bin/[ba|z|c]sh
line at the top of your script to ensure a proper execution environment. In the absence of such a line, the root
user’s login shell will be selected as the environment for running the script, which may produce inconsistent behavior or failures.
Be sure to specify the file extension when naming your configuration and teardown scripts. Arcus supports shell (.[ba|z|c]sh
) scripts for Linux and PowerShell (.ps1
) scripts for Windows machines. If you fail to add the correct file extension, the system will use the default file type for the OS selected, which may cause an error.
Always use the appropriate syntax and markdown for the script type indicated. Testing your syntax using a third-party checking tool is a good practice when setting up configuration and teardown scripts.
When writing your configuration or teardown scripts, keep in mind the install order and the Arcus deployment process. For example, configuration scripts that attempt to talk to a running application on the new machine will likely fail, because the deployment run is still in the process of building itself.
Another element to keep in mind is networking and connectivity. If your deployment run is on an isolated network, the script will be limited in its ability to reach the machine in question.
More Help
Review this topic with our video tutorials:
If you’re having trouble generating a configuration or teardown script in Arcus or need additional assistance, don’t hesitate to contact support.