Skip to content

Run a script when a node starts

View as Markdown

A start script runs on your node every time it starts, including every reboot. Use it to skip the manual work of connecting after every boot to install a package, mount something, or start a service yourself.

While creating the node, open Advanced settings and check Add Start Script. Paste your script into the field that appears (up to 2,048 characters), then continue through the summary and click Launch. Once the node finishes creating and starts running, your script runs on its own, before you connect to it.

The script runs again on every reboot. For anything you want to happen only once, add a check inside the script itself. For example, test for a marker file at the start, and skip the rest if it is already there. On Ubuntu, that looks like this:

#!/bin/bash
[ -f /var/lib/first-boot-done ] && exit 0
apt-get update && apt-get install -y nginx
touch /var/lib/first-boot-done

To check that the script ran, connect to the node and look for what it should have done: the package installed, the service running, or the marker file in place. See Connect to a Linux node.