Managing lifecycle scripts
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 l40s-48gb.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 console:
- From the console, select Compute > Instances in the left nav.
- Click Create Instance and begin the instance creation flow.
- When you reach the Lifecycle Scripts step, enter your startup and/or shutdown scripts. These are saved in
/usr/local/bin/crusoeon the VM. - Click Create Instance.
Modifying lifecycle scripts
You can modify an existing lifecycle script directly on the VM by editing the files in /usr/local/bin/crusoe. Changes 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'"