Skip to main content
Crusoe Support Help Center home page
Crusoe

How-To Prevent Re-Execution of Crusoe Lifecycle Scripts

Apeksha Khilari
Apeksha Khilari
Updated

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

  1. 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 immutable

    This 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/scriptran to indicate completion.

    Note: Force deletion of the marker file will re-enable script execution on next VM reboot.

After VM creation

  1. SSH into the VM.
  2. Modify the script to remove/comment out everything except #!/bin/bash .

    $ echo '#!/bin/bash' | sudo tee /usr/local/bin/crusoe/startup > /dev/null
  3. Stop/Start the VM.
  4. 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

 

Related to

Was this article helpful?

0 out of 0 found this helpful

Still need help?

Our support team is ready to assist you with any questions.

Have more questions? Submit a request

Recently Viewed

Comments

0 comments

Article is closed for comments.