To proceed with maintenance, stop and start virtual machines manually or automatically. If you need to keep your VMs running, contact the support team and consult them about the possibility of rescheduling maintenance of the affected VMs.
Do not stop your VM by using Linux commands, such as shutdown or halt. Compute considers this as a failure, reboots the VM automatically and continues charging for this VM. Use Nebius AI Cloud interfaces instead and follow the instructions below.
How to stop and start VMs automatically by using autohealing
You can create a VM with the autohealing function. It allows a VM to automatically stop and start each time maintenance is scheduled. As a result, the applications on this VM are highly available.
Use autohealing only if the automatic VM shutdown is safe for the workloads on this VM. If you cannot stop the VM at any time, it is better to manage the VM manually.
To create a VM that stops and starts automatically during maintenance events:
#!/bin/bashINSTANCE_ID_FILE="/mnt/cloud-metadata/instance-id"CHECK_INTERVAL=600 # 10 minutes in seconds# Check if the Nebius AI Cloud CLI is installedcheck_nebius_installed() { if ! command -v nebius &> /dev/null; then echo "$(date) - Nebius utility not found, exiting..." exit 1 fi}get_instance_id() { if [[ -f "$INSTANCE_ID_FILE" ]]; then cat "$INSTANCE_ID_FILE" else echo "File with the virtual machine ID is not found" exit 1 fi}# Handle a maintenance eventhandle_maintenance_event() { # Add custom actions before stopping the virtual machine echo "$(date) - Custom actions before stopping the virtual machine" sudo shutdown -h +1 "Restarting virtual machine due to maintenance"}check_nebius_installed# main loopwhile true; do INSTANCE_ID=$(get_instance_id) if [[ -z "$INSTANCE_ID" ]]; then echo "Virtual machine ID is empty" exit 1 fi RESPONSE=$(nebius compute instance get --id "$INSTANCE_ID" --format json) if echo "$RESPONSE" | jq -e '.status.maintenance_event_id' >/dev/null; then echo "$(date) - Maintenance event detected" handle_maintenance_event else echo "$(date) - No maintenance event detected" fi sleep "$CHECK_INTERVAL"done
Make the file executable:
Copy
Ask AI
sudo chmod +x /usr/local/bin/vm_maintenance.sh
To make the script run continuously and restart it when the VM fails or reboots, add a systemd unit to the script: