LogoLogo
Foundry Documentation
Foundry Documentation
  • Welcome to Foundry
  • Quickstart guide
  • Compute & Storage
    • Compute overview
    • Instance types & specifications
    • Reserving compute
    • Spot bids
      • Spot auction mechanics
    • Startup scripts
    • Access & manage instances
      • Statuses
    • Compute quotas
    • Managing open ports
    • Persistent storage
      • File shares
      • Block storage
    • Ephemeral storage
  • Foundry API
    • API overview and quickstart
    • API reference
      • Projects
      • Instance types
      • SSH Keys
      • Volumes
      • Instances
      • Spot
        • Bids
        • Availability
      • API Keys
      • Profile
    • Specification
  • Access Management
    • Access Management Overview
    • SSH keys
  • Account and Billing
    • Billing overview
    • Foundry Referral Program
  • Security & trust
    • Foundry's approach to security
    • Reporting security concerns
Powered by GitBook
LogoLogo

© 2025 Foundry Technologies, Inc.

On this page
  • Creating a startup script
  • Accessing start-up script and logs
  • Running scripts on subsequent startups after relocation, preemption, or resuming a spot bid
  1. Compute & Storage

Startup scripts

PreviousSpot auction mechanicsNextAccess & manage instances

Last updated 14 days ago

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 . Learn more about relocation and preemption statuses .

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 must start with #!/bin/bash and are limited to a maximum length of 10,000 characters.

Accessing start-up script and logs

To access your start-up script from your instance, run the following command:

cat /var/lib/foundry/startup_script.sh

To access any start-up script logs from your instance, run the following command:

cat /var/log/foundry/startup_script.log

Running scripts on subsequent startups after relocation, preemption, or resuming a spot bid

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, preempted, restarted, or resumed.

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."

here
run scripts on boot after relocation or preemption