Lifecycle scripts overview
Crusoe Cloud is currently in private beta. If you do not currently have access, please request access to continue.
Lifecycle scripts allow you to react to VM state changes, either a VM starting up or a VM shutting down, by running a shell script.
Startup scripts are run on VM boot after the network is accessible, and can run for an indefinite amount of time. Shutdown scripts are run when the VM gets a ACPI shutdown signal, and will run for up to 90 seconds, after which the VM will be terminated. Scripts run as root
and execute in the root directory (/
).
Creating lifecycle scripts
In order to create a lifecycle script, you need to create a VM with the script(s):
- CLI
- UI
Use the vm create
command to create a VM of your choice and pass in the path to a local script
crusoe compute vms create \
--name my-vm \
--type a40.1x \
--keyfile ~/.ssh/id_ed25519.pub \
--startup-script ~/path/to/startup.sh \
--shutdown-script ~/path/to/shutdown.sh
To create a VM with Lifecycle Scripts via the Crusoe Cloud console:
- Visit the Crusoe Cloud console
- Click the "Compute" tab in the left nav
- Click the "Instances" tab on the top bar
- Click the "Create Instance" button and begin the instance creation flow
- When you reach the "Lifecycle Scripts" step, enter your startup and/or shutdown scripts. These will be saved in
/usr/local/bin/crusoe
on the VM. - Click the "Create Instance" button
Modifying lifecycle scripts
Once a lifecycle script is created, you can modify the script directly on the VM by editing the files in /usr/local/bin/crusoe
. Changes to this script take effect immediately on the next shutdown or startup.
Limitations
Lifecycle scripts are subject to the following limitations:
- Scripts must be in
bash
(has to start with#!/bin/bash
) - Scripts must be less than 64kB in size
- Scripts may only contain ASCII characters
Example
"startup_script": "#!/bin/bash\necho 'hello'"