Last Updated: Nov 20, 2025
Introduction
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. 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.
This guide shows you how to add logic to your script that prevents it from running in the future, giving you more control over its execution.
Prerequisites
- Access to the Crusoe CLI or UI
- Valid Crusoe authentication credentials
Step-by-Step Instructions
Lifecycle scripts can be configured to prevent them from running on subsequent reboots.
During VM creation
-
Add a marker to your lifecycle script during VM creation.
$ cat /usr/local/bin/crusoe/startup #!/bin/bash marker=/usr/local/bin/crusoe/scriptran if [[ -f $marker ]];then echo "Startup script already ran. Exiting." exit fi <lifecycle code> touch $marker chattr +i $marker # Make the marker file immutableThis script checks if a marker file exists to prevent re-running the script, and if it hasn't run before, it executes the main code and then creates the marker file
/usr/local/bin/crusoe/scriptranto indicate completion.Note: Force deletion of the marker file will re-enable script execution on next VM reboot.
After VM creation
- SSH into the VM.
-
Modify the script to remove/comment out everything except
#!/bin/bash.$ echo '#!/bin/bash' | sudo tee /usr/local/bin/crusoe/startup > /dev/null - Stop/Start the VM.
- Verify the script hasn't run by watching required logs using tool such as
journalctl.
Note: You can delete or rename the startup and shutdown scripts in /usr/local/bin/crusoe, but this method will clutter your log history with errors. You can find them on querying with journalctl -u lifecycle-script.service.
Additional Resources