Skip to main content

Rebooting Instances

Rebooting an instance performs a graceful restart of the virtual machine, similar to restarting your computer. This is useful for applying system updates, clearing memory, or resolving temporary issues.

When to Reboot an Instance

  • Apply system updates that require a restart
  • Clear memory leaks or resolve performance issues
  • Reset network configurations that may have become corrupted
  • Recover from software hangs without losing data
  • Apply configuration changes that require a system restart

Reboot an Instance

Restart a running instance gracefully:

from morphcloud.api import MorphCloudClient

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with your instance ID

# Get the instance and reboot it
instance = client.instances.get(instance_id=instance_id)
instance.reboot()

print(f"Instance {instance_id} is rebooting...")
print(f"Current status: {instance.status}")

Force Reboot

Perform a hard reboot when a graceful reboot doesn't work:

from morphcloud.api import MorphCloudClient

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with your instance ID

# Force reboot the instance
instance = client.instances.get(instance_id=instance_id)
instance.reboot(force=True)

print(f"Force rebooting instance {instance_id}...")

Monitor Reboot Progress

Check the status during and after reboot:

from morphcloud.api import MorphCloudClient
import time

client = MorphCloudClient()

instance_id = "morphvm_abc123" # Replace with your instance ID

# Reboot and monitor status
instance = client.instances.get(instance_id=instance_id)
instance.reboot()

print(f"Rebooting {instance_id}...")

# Monitor reboot progress
for i in range(12): # Check for up to 2 minutes
time.sleep(10)
instance = client.instances.get(instance_id=instance_id)
print(f"Status: {instance.status}")

if instance.status == "ready":
print("Reboot completed successfully!")
break
elif instance.status == "error":
print("Reboot failed!")
break

Best Practices

  • Create a snapshot before rebooting if you've made important changes
  • Use graceful reboot first - only force reboot if necessary
  • Monitor reboot progress to ensure successful completion
  • Wait for "ready" status before performing other operations

Rebooting helps maintain instance health and apply necessary system changes while preserving your data and configurations.