How to Manage Startup Scripts for Vultr Instances

Updated on November 27, 2024

Startup Scripts for Vultr instances are files that run custom commands when your instances boot. The scripts automate repetitive tasks like installing software, configuring settings, querying third-party services, and more. These scripts are suitable when provisioning multiple Cloud Compute instances because they save time.

Follow this guide to manage Startup Scripts for Vultr Instances using the Vultr Customer Portal, API, and CLI.

  • Vultr Customer Portal
  • Vultr API
  • Vultr CLI
  1. Navigate to Orchestration and select Scripts.

  2. Click Add Startup Script.

    Add Startup Script

  3. Enter a name, select the type, define some commands, and click Add Script.

    Script Details

  1. Send a POST request to the Create Startup Script endpoint and encode the Startup script to Base64 format.

    console
    $ curl "https://api.vultr.com/v2/startup-scripts" \
        -X POST \
        -H "Authorization: Bearer ${VULTR_API_KEY}" \
        -H "Content-Type: application/json" \
        --data '{
            "name" : "Sample-Script",
            "type" : "pxe",
            "script" : "QmFzZTY0IEV4YW1wbGUgRGF0YQ=="
        }'
    

    Visit the Create Startup Script endpoint to view additional attributes to add to your request.

  2. Send a GET request to the List Startup Scripts endpoint to view all scripts.

    console
    $ curl "https://api.vultr.com/v2/startup-scripts" \
        -X GET \
        -H "Authorization: Bearer ${VULTR_API_KEY}"
    
  1. Create a new scripts.yaml file.

    console
    $ nano scripts.yaml
    
  2. Enter your Startup scripts into the file.

    yaml
    mkdir ~/my-apps
    chmod 700 ~/my-apps
    
  3. Save the file.

  4. Convert the file contents to Base64 and note the output. For instance, bWtkaXIgfi9teS1hcHBzCmNobW9kIDcwMCB+L215LWFwcHM=.

    console
    $ echo -n "$(<scripts.yaml)" | base64
    
  5. Create a new Startup script.

    console
    $ vultr-cli script create \
    --name Sample-Script \
    --type boot \
    --script bWtkaXIgfi9teS1hcHBzCmNobW9kIDcwMCB+L215LWFwcHM=
    
  6. List all scripts.

    console
    $ vultr-cli script list
    
  7. Get the details of a specific script by specifying a script ID.

    console
    $ vultr-cli script get script_id
    

    Run vultr-cli script create --help to view all options.