Table of Contents

Running the server

The same server runs as a console app, a systemd service or a Windows service. The host works out which one it is from how the process was started, so the code doesn't change. Each way stops the same way, through the shutdown described in The game loop.

The server runs on Linux, Windows and macOS, the systems where QUIC is available. On anything else, the host stops at startup with a PlatformNotSupportedException.

As a console app

Run it with dotnet run, or run the published executable. Ctrl+C stops it. Log messages go to the console, as described in Logging.

As a systemd service

When systemd starts the process, the host uses systemd's lifetime. It tells systemd when it has started and when it is stopping, and systemd's stop, a SIGTERM, runs the usual shutdown. The check is made by Microsoft.Extensions.Hosting.Systemd, so a process started by hand from a shell is a console app.

Use Type=notify, so that systemd waits for the server's start notice before it considers the service started:

[Service]
ExecStart=/opt/mygame/MyGame.Server
Type=notify
Restart=on-failure

As a Windows service

When the Windows Service Control Manager starts the process, the host runs as a Windows service. Register the executable with the service manager, for example with sc.exe create. Stopping the service runs the usual shutdown. A process started from a command prompt is a console app.

Where the server looks for files

  • The content root, which is where the host looks for appsettings.json, is the executable's folder. It is the same whatever the working directory is, which matters because a service manager often starts a process from another folder.
  • Configuration: the host's default configuration reads appsettings.json, appsettings.<Environment>.json, environment variables and command-line arguments, and makes them available as IConfiguration. BSGameLib does not read its settings from them: they are set in code, as described in The host and its settings. The configuration files are not watched for changes.
  • Plugins are the .dll and .exe files in the executable's folder. The host scans them as described in How it finds your code.
  • The data folder holds the server's own files: the generated certificate, in certs. It is the executable's folder, unless your IServerSettings gives another in DataFolder.

Ports

The server uses UDP only. It listens on ListenPort, which is 55237 by default, for QUIC. It also binds ListenPort plus 2, for unreliable traffic, so 55239 by default. Open both in a firewall. ListenPort plus 1 is not used.

By default the server listens on every address: IPv6 and IPv4 together where the host has IPv6. Set BindAddress in the host's settings to listen on one address only, such as 127.0.0.1 for a server that only this machine should reach. It applies to both ports.