# Machines

## Table of Contents

1. [Overview](#1-overview)
2. [Browsing Machines](#2-browsing-machines)
3. [Current Machine Page](#3-current-machine-page)
4. [Registering a Machine](#4-registering-a-machine)
5. [Updating Machine Details](#5-updating-machine-details)
6. [Managing Background Services](#6-managing-background-services)

***

## 1. Overview

Machines in Axilon represent the physical or virtual systems that run your applications. The Machines section provides two views:

* **List Machines** -- A table of all machines registered across the system.
* **Current Machine** -- A detailed dashboard for the machine you are currently running Axilon on.

***

## 2. Browsing Machines

### Steps

1. Click **Machines > List Machines** in the sidebar.
2. The page displays a paginated table (5 machines per page by default).

### Table Columns

| Column             | What It Shows                                                  |
| ------------------ | -------------------------------------------------------------- |
| **Avatar**         | A visual indicator for the machine.                            |
| **Name**           | The machine's registered name.                                 |
| **Type**           | A chip showing **"Clone"** or **"Primary"**.                   |
| **Status**         | A color-coded chip: green for **Online**, red for **Offline**. |
| **Last Online At** | The date and time the machine was last seen online.            |
| **Created By**     | The user who registered the machine.                           |
| **Created At**     | The registration date.                                         |

### Filtering

Use the **Application** filter above the table to narrow results to machines associated with a specific application.

***

## 3. Current Machine Page

The Current Machine page provides a detailed dashboard for the machine you are running the application on.

### Steps

1. Click **Machines > Current Machine** in the sidebar.

### What You See

**Machine Stats** (4 cards across the top)

| Stat               | Description                                                                |
| ------------------ | -------------------------------------------------------------------------- |
| **Name**           | Machine name with a desktop icon (green if online, grayed out if offline). |
| **Status**         | Current status: Online or Offline.                                         |
| **Last Online At** | When the machine was last seen online.                                     |
| **Created By**     | The user who registered it.                                                |

**Machine Description Card**

* Description text.
* Registration date.
* Platform badge showing the operating system name, version, and platform icon.

**Background Services Card**

* Lists all Axilon background services running on the machine.
* Shows the application version.
* Displays an elevation status badge (Standard, Elevating, Elevated, Elevation Failed, or Cancelled).
* Each service shows its name, status indicator, type icon, and individual action buttons.
* A menu button provides bulk service actions.

### If the Machine Is Not Registered

If the current machine has not been registered yet, an alert banner appears with a **"Register"** button (Global Admin only). See [Section 4](#4-registering-a-machine) for registration steps.

***

## 4. Registering a Machine

> **Required role:** Global Admin

### Steps

1. Navigate to **Machines > Current Machine**.
2. If the machine is not yet registered, click **"Register"** in the header.
3. Fill out the registration form:

| Field                   | Required | Rules                               | Notes                                                                                          |
| ----------------------- | :------: | ----------------------------------- | ---------------------------------------------------------------------------------------------- |
| **Name**                |    Yes   | 5--30 characters                    | A unique, human-readable name for the machine.                                                 |
| **IP Address**          |    Yes   | Valid IPv4 format                   | The machine's network address.                                                                 |
| **TCP/UDP Ports**       |    Yes   | At least 1 port; each port 1--65535 | Add ports with their protocol (TCP or UDP). Duplicates with the same protocol are not allowed. |
| **Description**         |    Yes   | 1--128 characters                   | Describe the machine's purpose.                                                                |
| **Health Check Script** |    No    | --                                  | Optional script for health monitoring.                                                         |
| **OS Name**             |   Auto   | Auto-detected                       | The operating system name (auto-detected, can be overridden).                                  |
| **OS Version**          |   Auto   | Auto-detected                       | The operating system version (auto-detected, can be overridden).                               |

4. Click **"Register"**.
5. On success, a *"Machine was registered successfully"* notification appears. The system then:
   * Saves the machine details locally.
   * Activates the machine.
   * Sets up and starts background services.

### Adding Ports

* Click **"Add port"** to add a new port entry.
* Select the protocol (**TCP** or **UDP**) and enter the port number (1--65535).
* The add button is disabled until the current port is valid and unique.
* Click the remove icon next to a port to delete it.

### If Registration Fails

An error notification appears: *"Registration was not successful, please try again."* If activation fails after registration, the system automatically cleans up the partially registered machine.

***

## 5. Updating Machine Details

> **Required role:** Global Admin

### Steps

1. Navigate to **Machines > Current Machine**.
2. Click **"Update"** in the header.
3. The form is pre-filled with the machine's current values. All registration fields can be edited.
4. Make your changes and click **"Update"**.
5. On success, a *"Machine details updated successfully!"* notification appears.

***

## 6. Managing Background Services

The Background Services card on the Current Machine page shows all Axilon services running on the machine.

### Reading the Services List

Each service row shows:

| Element              | Description                                      |
| -------------------- | ------------------------------------------------ |
| **Service name**     | The name of the background service.              |
| **Status indicator** | Visual indicator of the service's current state. |
| **Type icon**        | The service type.                                |
| **Warning icon**     | Appears if the service has an error.             |
| **Action buttons**   | Start or Stop, depending on the current state.   |

### Individual Service Actions

| Action    | Available When      |
| --------- | ------------------- |
| **Start** | Service is stopped. |
| **Stop**  | Service is running. |

Actions are not available during transition states (Starting, Stopping, Installing, Uninstalling).

### Bulk Actions

Click the menu button on the Background Services card header to access bulk operations:

| Action           | Description                                                                                                       |
| ---------------- | ----------------------------------------------------------------------------------------------------------------- |
| **Install**      | Sets up all background services. Requires administrator elevation.                                                |
| **Uninstall**    | Removes all background services. Requires administrator elevation.                                                |
| **Start All**    | Starts all stopped services.                                                                                      |
| **Stop All**     | Stops all running services.                                                                                       |
| **Resync Token** | Refreshes the authentication token for all services. Uninstalls and reinstalls services with updated credentials. |

### Elevation Status

Some bulk operations (Install, Uninstall) require administrator elevation on Windows. The elevation status badge in the card header shows:

| Status               | Meaning                                          |
| -------------------- | ------------------------------------------------ |
| **Standard**         | Normal user privileges.                          |
| **Elevating**        | Elevation is in progress.                        |
| **Elevated**         | Administrator privileges are active.             |
| **Elevation Failed** | The elevation request was denied or failed.      |
| **Cancelled**        | The elevation request was cancelled by the user. |
