Startup scripts

Startup scripts perform tasks during the initial startup process of your instances. They can be used to automatically configure your environment and workloads, alleviating manual setup. See Instance types & specifications for information on what Foundry installs by default on all instances.

Startup scripts only run the first time your instance starts up. Your startup script will not run again if your instance is relocated or preempted and allocated at a later time. You can use a systemd service to run scripts on boot after relocation or preemption. Learn more about relocation and preemption statuses here.

Creating a startup script

You have the option to add a startup script each time you create a new reservation or spot bid. Startup scripts must be added before submitting your reservation or bid; they cannot be added later.

You can add a startup script to your reservation or bid in the Foundry console by attaching a bash or txt file or manually typing a script into the startup script field.

Startup scripts are limited to a maximum length of 10,000 characters.

Running scripts on subsequent startups after relocation or preemption

The startup script added when creating your reservation or spot bid is only executed the first time your instance starts up. It will not run again if your instance is relocated or preempted.

However, because Foundry preserves the boot disk for your spot instances until you fully terminate your spot bid, you can use systemd services to implement logic that restarts your workload the next time your spot instances start up after being relocated or preempted. You can use your initial startup script to set up a systemd service.

Here is a simple example of a startup script that creates a hello-world.sh script and a systemd service, startup.service, which will run hello-world.sh on all subsequent startups:

#!/bin/bash

# Create the .sh file we want to run on startup
sudo tee -a /usr/local/sbin/hello-world.sh >/dev/null << 'EOF'
#!/bin/bash
echo “Hello World!”
EOF

# Make the .sh file executable
sudo chmod +x /usr/local/sbin/hello-world.sh

# Create a .service file to define a systemd service 
sudo tee -a /etc/systemd/system/startup.service >/dev/null << 'EOF'
[Unit]
Description=My Startup Script

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/hello-world.sh

[Install]
WantedBy=multi-user.target
EOF

# Enable services to run on boot
sudo systemctl enable startup.service

echo "hello-world.sh will run on subsequent startups."

Last updated