Skip to main content
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 manually

  1. In the sidebar, go to icon Compute → Virtual machines.
  2. Find VMs with the maintenance label.
    maintenance-label
  3. Click icon → Stop for these VMs.
  4. In the window that opens, confirm stopping the VM.
  5. When the VM status changes to Stopped, click icon → Start.
  6. In the window that opens, confirm starting the VM.

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:
  1. Create a service account.
  2. Add it to the default viewers group:
    1. Get the ID of the viewers group:
      nebius iam group get-by-name --name viewers \
        --parent-id <tenant_ID> \
        --format json | jq -r '.metadata.id'
      
      To get the tenant ID, go to the web console and expand a top-left list of projects. Next to the tenant’s name, click iconCopy tenant ID.
    2. Get the ID of the service account:
      nebius iam service-account get-by-name \
        --name <service_account_name> \
        --format json | jq -r '.metadata.id'
      
    3. Add the service account to the viewers group:
      nebius iam group-membership create \
        --parent-id <viewers_group_ID> \
        --member-id <service_account_ID>
      
  3. Create a VM. In its configuration, specify the following:
    • Settings that allow connections to this VM.
    • Created service account:
      nebius compute instance create \
      - <<EOF
      {
        "spec": {
          ...
          "service_account_id": "<service_account_ID>"
        },
        ...
      }
      EOF
      
  4. Connect to the VM.
  5. Install jq on the VM:
    sudo apt-get install jq
    
  6. Go to the /usr/local/bin/ directory:
    cd /usr/local/bin/
    
  7. Create the vm_maintenance.sh file:
    sudo nano vm_maintenance.sh
    
  8. Add the following Bash script to the file:
    #!/bin/bash
    
    INSTANCE_ID_FILE="/mnt/cloud-metadata/instance-id"
    CHECK_INTERVAL=600 # 10 minutes in seconds
    
    # Check if the Nebius AI Cloud CLI is installed
    check_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 event
    handle_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 loop
    while 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
    
  9. Make the file executable:
    sudo chmod +x /usr/local/bin/vm_maintenance.sh
    
  10. To make the script run continuously and restart it when the VM fails or reboots, add a systemd unit to the script:
    sudo bash -c 'cat > /etc/systemd/system/vm_maintenance.service << EOF
    [Unit]
    Description=VM Maintenance Event Handler
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/vm_maintenance.sh
    Restart=always
    User=root
    Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    WorkingDirectory=/usr/local/bin
    StandardOutput=append:/var/log/vm_maintenance.log
    StandardError=append:/var/log/vm_maintenance.log
    
    [Install]
    WantedBy=multi-user.target
    EOF'
    
  11. Start the service created with the systemd unit, and let it restart in case of the VM reboot:
    sudo systemctl daemon-reload
    sudo systemctl start vm_maintenance
    sudo systemctl enable vm_maintenance
    sudo systemctl status vm_maintenance
    
    The output example is the following:
    Created symlink /etc/systemd/system/multi-user.target.wants/vm_maintenance.service → /etc/systemd/system/vm_maintenance.service.
    ● vm_maintenance.service - VM Maintenance Event Handler
         Loaded: loaded (/etc/systemd/system/vm_maintenance.service; enabled; vendor preset: enabled)
         Active: active (running) since Fri 2025-04-25 10:19:19 UTC; 214ms ago
       Main PID: 28530 (vm_maintenance.)
          Tasks: 6 (limit: 19056)
         Memory: 24.3M
            CPU: 25ms
         CGroup: /system.slice/vm_maintenance.service
                 ├─28530 /bin/bash /usr/local/bin/vm_maintenance.sh
                 └─28535 nebius compute instance get --id computeinstance-*** --format json
    
    Apr 25 10:19:19 computeinstance-*** systemd[1]: Started VM Maintenance Event Handler.
    
Now, the script runs continuously, and the VM stops and starts during maintenance events.