Skip to content

Instantly share code, notes, and snippets.

@robinknowles
Created September 21, 2023 11:00
Show Gist options
  • Save robinknowles/0cc645f5afd0375f5d86803dff7d62d9 to your computer and use it in GitHub Desktop.
Save robinknowles/0cc645f5afd0375f5d86803dff7d62d9 to your computer and use it in GitHub Desktop.
Detecting an AWS spot instance interruption during an OpenFOAM simulation & saving your data

Detecting AWS spot instance interruptions in OpenFOAM

Accompanies OnCFD Newsletter #165

Here's a quick OpenFOAM function that makes running on AWS spot instances a whole lot nicer.

It uses two standard function objects (plus curl) to check whether your instance has recieved a termination notice.

If it has, it stops your simulation & writes your current data.

If it hasn't, it keeps on iterating (& checking).

checker
{
    type	systemCall;
    libs	(utilityFunctionObjects);

    master	true;

    executeControl		clockTime;
    executeInterval		10;

    writeControl		$executeControl;
    writeInterval		$executeInterval;

    executeCalls
    (
    "echo Checking for spot interrupt"
    "curl --fail --silent --output OF.interrupt http://169.254.169.254/latest/meta-data/spot/instance-action"
    );
}

interupt
{
    type	abort;
    libs	(utilityFunctionObjects);

    file    "OF.interrupt";
    action  writeNow;
}

Save it to your system directory, add it to the functions section of your controlDict & give it a go.

For more info see the original article 👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment