> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nelieo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run and Manage the NSP Axon Daemon Windows Service

> Install, start, stop, and troubleshoot the NSPDaemon Windows Service, including Event Log access and common failure recovery steps.

The NSP daemon is designed to run as a Windows Service named `NSPDaemon`. Running as a service means the daemon starts automatically when Windows boots, continues running without a logged-in user session, and restarts automatically after transient failures. The GUI installer sets all of this up for you — the commands below let you manage and troubleshoot the service at any time.

## Service Overview

<CardGroup cols={2}>
  <Card title="Service name" icon="tag">
    `NSPDaemon` — use this in all PowerShell and `sc.exe` commands.
  </Card>

  <Card title="Display name" icon="subtitles">
    `NSP Daemon` — shown in `services.msc` and Task Manager.
  </Card>

  <Card title="Start type" icon="play">
    **Automatic** — starts on every Windows boot without user interaction.
  </Card>

  <Card title="Failure recovery" icon="rotate">
    Auto-restarts on failure: 30 s after first, 60 s after second, 120 s after subsequent failures.
  </Card>
</CardGroup>

## Checking Service Status

```powershell theme={null}
Get-Service -Name NSPDaemon
```

You will see output similar to:

```text theme={null}
Status   Name               DisplayName
------   ----               -----------
Running  NSPDaemon          NSP Daemon
```

A `Status` of `Running` means the daemon is active and the API on `localhost:7842` should be responsive. Confirm with the health check:

```powershell theme={null}
curl http://localhost:7842/health
```

## Starting, Stopping, and Restarting

Use these PowerShell commands to control the service lifecycle. Run them in an Administrator PowerShell session.

```powershell theme={null}
# Start the service
Start-Service -Name NSPDaemon

# Stop the service
Stop-Service -Name NSPDaemon

# Restart the service (applies config changes, clears stuck state)
Restart-Service -Name NSPDaemon
```

You can also manage the service visually by opening **Services** (`services.msc`) and locating **NSP Daemon** in the list.

<Note>
  Changes to `[server]` settings in `axon.toml` (port, host) require a service restart to take effect. Most other configuration changes are picked up live. See [Configuration](/daemon/configuration).
</Note>

## Installing and Uninstalling the Service

If you used the GUI installer, the service is already registered. Use these commands for manual or scripted deployments.

<Steps>
  <Step title="Install the service">
    Run this in an Administrator PowerShell session. This registers `NSPDaemon` with the Windows Service Control Manager and configures automatic start and failure recovery.

    ```powershell theme={null}
    axon-daemon.exe install
    ```

    Expected output:

    ```
    ✅ Service 'NSPDaemon' installed successfully
       Display name: NSP Daemon
       Start type: Automatic
       Restart on failure: Yes (3 attempts, 30s delay)
    ```
  </Step>

  <Step title="Start the service">
    ```powershell theme={null}
    axon-daemon.exe start
    ```

    Alternatively, use `Start-Service -Name NSPDaemon` directly from PowerShell.
  </Step>

  <Step title="Verify it is running">
    ```powershell theme={null}
    Get-Service -Name NSPDaemon
    curl http://localhost:7842/health
    ```
  </Step>
</Steps>

To remove the service entirely:

```powershell theme={null}
# Stop the service first, then unregister it
axon-daemon.exe stop
axon-daemon.exe uninstall
```

<Warning>
  Uninstalling the service does not delete `axon-daemon.exe` or your configuration files under `C:\ProgramData\Nelieo`. Run `axon-daemon.exe install` again at any time to re-register with the same configuration.
</Warning>

## Configuring Failure Recovery

The installer sets sensible defaults for automatic restart on failure. To customize the recovery schedule, use `sc.exe` as Administrator:

```powershell theme={null}
# Restart after 30s on first failure, 60s on second, 120s on all subsequent failures
# reset= 86400 resets the failure count after 24 hours of clean uptime
sc.exe failure NSPDaemon reset= 86400 actions= restart/30000/restart/60000/restart/120000
```

## Running as a Least-Privilege Account

By default, the service runs as **Local System**. For production environments, create a dedicated low-privilege account to limit the service's access to the rest of the system:

```powershell theme={null}
# Create a dedicated service account with no password (managed by Windows)
New-LocalUser -Name "nsp-service" -NoPassword -Description "NSP Daemon service account"

# Grant the account Modify access to the config directory
$acl = Get-Acl "C:\ProgramData\Nelieo"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(
    "nsp-service", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow"
)
$acl.SetAccessRule($rule)
Set-Acl "C:\ProgramData\Nelieo" $acl

# Configure the service to run under this account
sc.exe config NSPDaemon obj= ".\nsp-service" password= ""
```

<Tip>
  After changing the service account, restart the service with `Restart-Service -Name NSPDaemon` and confirm the health check still returns `"status": "ok"`.
</Tip>

## Checking the Windows Event Log

The daemon writes structured events to the Windows Event Log under the **Application** log, source `NSPDaemon`. This is the first place to look when the service fails to start or exits unexpectedly.

```powershell theme={null}
# View the 50 most recent events from the daemon
Get-EventLog -LogName Application -Source NSPDaemon -Newest 50

# Filter to errors and warnings only
Get-EventLog -LogName Application -Source NSPDaemon -Newest 50 |
    Where-Object { $_.EntryType -in "Error", "Warning" }
```

You can also use the GUI:

1. Open **Event Viewer** (`eventvwr.msc`)
2. Expand **Windows Logs → Application**
3. Click **Filter Current Log** and set **Event sources** to `NSPDaemon`

## Troubleshooting Common Service Failures

<AccordionGroup>
  <Accordion title="Service stops immediately after starting">
    The most common cause is a configuration error in `axon.toml`. Check the Windows Event Log for a startup error message:

    ```powershell theme={null}
    Get-EventLog -LogName Application -Source NSPDaemon -Newest 10
    ```

    Then validate your config by running the daemon in foreground mode — it prints config errors directly to the terminal:

    ```powershell theme={null}
    Stop-Service -Name NSPDaemon
    axon-daemon.exe run
    ```

    Fix any errors reported, then restart the service.
  </Accordion>

  <Accordion title="Port 7842 is already in use">
    Another process is bound to port 7842. Find it and either stop it or change the daemon's port in `axon.toml`:

    ```powershell theme={null}
    # Find the process using port 7842
    netstat -ano | findstr :7842

    # Look up the PID
    Get-Process -Id <PID>
    ```

    To change the daemon port, update `[server] port` in `axon.toml` and restart the service. Remember to update any SDK clients and agents that connect to the old port.
  </Accordion>

  <Accordion title="Service fails to start: Access Denied">
    If you configured a custom service account and the service reports **Access Denied**, the account likely does not have permission to read `axon.toml` or write to the log directory. Re-run the ACL commands in the [Running as a Least-Privilege Account](#running-as-a-least-privilege-account) section above, then restart the service.
  </Accordion>

  <Accordion title="Health check returns Connection Refused">
    `Connection refused` on port 7842 means the daemon process is not running. Check the service status:

    ```powershell theme={null}
    Get-Service -Name NSPDaemon
    ```

    If `Status` is `Stopped`, check the Event Log for the exit reason, then start the service:

    ```powershell theme={null}
    Start-Service -Name NSPDaemon
    ```

    If the service repeatedly stops, run it in foreground mode to see the error output directly in the terminal.
  </Accordion>

  <Accordion title="Service is Running but health check hangs">
    The daemon process is alive but not responding to HTTP requests. This can happen if the daemon's async runtime has deadlocked or if another process is intercepting traffic on port 7842. Restart the service to recover:

    ```powershell theme={null}
    Restart-Service -Name NSPDaemon
    ```

    If the issue recurs frequently, enable `include_spans = true` in `[logging]` and share the span output with Nelieo support.
  </Accordion>
</AccordionGroup>

## Running in Foreground for Debugging

If you need interactive, real-time log output — for example, to trace a probe failure or test a configuration change — stop the service and run the daemon in foreground mode:

```powershell theme={null}
# Stop the service so both instances do not compete for port 7842
Stop-Service -Name NSPDaemon

# Run interactively with debug logging
axon-daemon.exe run --log-level debug
```

Press `Ctrl+C` to stop. The binary is identical to the one the service uses — `run` is just a startup mode, not a different build. When you are done debugging, restart the service:

```powershell theme={null}
Start-Service -Name NSPDaemon
```
