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:
- Python
- TypeScript
- CLI
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}")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function rebootInstance() {
const instance_id = "morphvm_abc123"; // Replace with your instance ID
// Get the instance and reboot it
const instance = await client.instances.get({ instance_id: instance_id });
await instance.reboot();
console.log(`Instance ${instance_id} is rebooting...`);
console.log(`Current status: ${instance.status}`);
}
rebootInstance();
# Reboot an instance
morphcloud instance reboot morphvm_abc123
Force Reboot
Perform a hard reboot when a graceful reboot doesn't work:
- Python
- TypeScript
- CLI
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}...")
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function forceRebootInstance() {
const instance_id = "morphvm_abc123"; // Replace with your instance ID
// Force reboot the instance
const instance = await client.instances.get({ instance_id: instance_id });
await instance.reboot({ force: true });
console.log(`Force rebooting instance ${instance_id}...`);
}
forceRebootInstance();
# Force reboot an instance
morphcloud instance reboot morphvm_abc123 --force
Monitor Reboot Progress
Check the status during and after reboot:
- Python
- TypeScript
- CLI
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
import { MorphCloudClient } from 'morphcloud';
const client = new MorphCloudClient();
async function monitorReboot() {
const instance_id = "morphvm_abc123"; // Replace with your instance ID
// Reboot and monitor status
let instance = await client.instances.get({ instance_id: instance_id });
await instance.reboot();
console.log(`Rebooting ${instance_id}...`);
// Monitor reboot progress
for (let i = 0; i < 12; i++) { // Check for up to 2 minutes
await new Promise(resolve => setTimeout(resolve, 10000));
instance = await client.instances.get({ instance_id: instance_id });
console.log(`Status: ${instance.status}`);
if (instance.status === "ready") {
console.log("Reboot completed successfully!");
break;
} else if (instance.status === "error") {
console.log("Reboot failed!");
break;
}
}
}
monitorReboot();
# Reboot and wait for completion
morphcloud instance reboot morphvm_abc123 --wait
# Or monitor manually
morphcloud instance reboot morphvm_abc123
morphcloud instance get morphvm_abc123 --watch
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.