Skip to content

Homelab-ready game server infrastructure. Deploy and manage Factorio, Palworld, and Terraria servers with Ansible, Terraform, and a Preact status dashboard.

License

Notifications You must be signed in to change notification settings

kidunot89/game-servers-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game Servers Linux

Monorepo for managing multiple dedicated game servers on Linux using Ansible for deployment and optionally Terraform for cloud infrastructure provisioning (DigitalOcean).

Supported Games

Game Port Protocol Service
Palworld 8211 UDP palworld.service
Terraria 7777 TCP terraria.service
Factorio Co-op 34197 UDP factorio-coop.service
Factorio PvP 34198 UDP factorio-pvp.service

Prerequisites

  1. Node.js (v18+): Required for deployment scripts
  2. Ansible: Installing Ansible
  3. SSH access to your game server
  4. Terraform (optional, for cloud deployment): Install Terraform

Project Structure

game-servers-linux/
├── servers/                      # Individual game server configurations
│   ├── palworld/
│   │   ├── ansible/              # Ansible playbook, roles, inventory
│   │   └── terraform/            # Terraform config for DigitalOcean
│   ├── terraria/
│   │   ├── ansible/
│   │   └── terraform/
│   └── factorio/
│       ├── ansible/
│       │   └── roles/factorio/files/saves/  # Seed save files
│       └── terraform/
├── status-app/                   # Server status web application
│   ├── src/                      # Preact SPA source
│   ├── server.ts                 # Fastify API server
│   └── ansible/                  # Deployment for status app
├── scripts/
│   ├── deploy.ts                 # Deployment script
│   ├── backup-saves.ts           # Backup saves from server
│   └── restore-save.ts           # Restore saves to server
├── backups/                      # Local save backups (gitignored)
├── servers.yml                   # Server definitions
├── host.yml                      # SSH connection details (gitignored)
├── host.dist.yml                 # Example host configuration
├── terraform.tfvars              # Shared Terraform variables (gitignored)
├── terraform.tfvars.dist         # Example Terraform variables
└── package.json

Setup

Local Server Deployment

  1. Clone the repository:

    git clone <repository-url>
    cd game-servers-linux
  2. Install dependencies:

    npm install
  3. Copy host.dist.yml to host.yml and configure your server details:

    ansible_host: "192.168.0.49"
    ansible_user: "your_username"
    ansible_ssh_private_key_file: "/home/you/.ssh/id_rsa"
    ansible_become_password: "your_sudo_password"
  4. Install Ansible collections:

    cd servers/<game>/ansible
    ansible-galaxy collection install -r roles/requirements.yml --force

Cloud Deployment (DigitalOcean with Terraform)

  1. Copy terraform.tfvars.dist to terraform.tfvars and configure:

    do_token     = "your_digitalocean_api_token"
    ssh_key_name = "your-ssh-key-name"
  2. Generate an SSH key pair (if needed):

    ssh-keygen -b 4096 -t rsa -C "your_email@example.com"
  3. Import your SSH public key to DigitalOcean:

    • Navigate to: Settings > Security > SSH Keys > Add SSH key
  4. Generate a Personal Access Token on DigitalOcean:

    • Navigate to: API > Tokens > Generate New Token (with read & write scopes)
  5. Initialize and apply Terraform:

    cd servers/<game>/terraform
    terraform init
    terraform apply -auto-approve
  6. To destroy cloud infrastructure:

    terraform destroy -auto-approve

Usage

Deploying Servers

Deploy all enabled servers:

npm run deploy:all

Deploy specific servers:

npm run deploy:palworld
npm run deploy:terraria
npm run deploy:factorio

Managing Saves

Backup current saves from the server:

npm run backup-saves

Restore a save to the server:

npm run restore-save -- --game factorio-coop --name MadMadWorld.zip

Server Management (via SSH)

Start/stop/restart a service:

ssh user@server "sudo systemctl start factorio-coop.service"
ssh user@server "sudo systemctl stop factorio-coop.service"
ssh user@server "sudo systemctl restart factorio-coop.service"

View logs:

ssh user@server "journalctl -u factorio-coop.service -f"

Server Configuration

servers.yml

Defines all game servers with display names, ports, services, and connection instructions.

Individual Server Inventory Files

Located at servers/<game>/ansible/inventory.yml. Contains server-specific variables like world settings, max players, and admin lists.

Example (Factorio):

factorio_admins:
  - username1
  - username2

factorio_instances:
  - name: "coop"
    display_name: "My Co-op Server"
    port: 34197
    save_file: "MadMadWorld.zip"
    max_players: 16

Role Defaults

Located at servers/<game>/ansible/roles/<game>/defaults/main.yml. Contains default values for all configuration options.

Status App

A web-based status page showing real-time server status, built with Preact and Fastify.

Development

Run locally for development:

npm run dev

This starts both:

  • Vite dev server on port 5173 (frontend)
  • Fastify API on port 3000 (backend)

Production Deployment

Build and deploy to the game server:

npm run build
npm run deploy:status

The status app runs as a systemd service behind nginx on the game server.

Factorio-Specific Features

Reset to Seed Saves

To wipe progress and restore original maps, set in inventory.yml:

factorio_reset_to_seed: true

Then run npm run deploy:factorio. Warning: This deletes all backups and overwrites current saves. Set back to false after running.

Non-blocking Saves

Enabled by default to prevent game stalls during autosaves.

Technology Stack

Component Technology
Deployment Scripts Node.js, TypeScript
Server Configuration Ansible
Cloud Infrastructure Terraform, DigitalOcean
Status App Frontend Preact, Vite
Status App Backend Fastify
Game Servers Systemd services
Firewall UFW

FAQ

Resolving Python crypt module deprecation warning

pip3 install passlib

Modifying Server Settings

  1. Edit the relevant inventory.yml or defaults/main.yml
  2. Run npm run backup-saves (recommended)
  3. Run npm run deploy:<game>

Viewing Server Status

ssh user@server "systemctl status factorio-coop.service"

Transferring Saves Between Servers

Use the backup/restore scripts:

# On old setup
npm run backup-saves

# Copy backups/ directory to new setup, then:
npm run restore-save -- --game factorio-coop --name MadMadWorld.zip

Making Servers Public (Local Servers Only)

Note: This section only applies if you're running game servers on a local machine (e.g., a home server). If you deployed via Terraform to DigitalOcean, your server already has a public IP and these steps are not needed.

To allow friends to connect from the internet to your home server, you need to configure port forwarding on your router.

Required Ports

Game Port Protocol
Palworld 8211 UDP
Terraria 7777 TCP
Factorio Co-op 34197 UDP
Factorio PvP 34198 UDP
Status App 80 TCP

Setup Steps

  1. Find your server's local IP address:

    hostname -I | awk '{print $1}'
  2. Access your router's admin panel (typically 192.168.0.1 or 192.168.1.1)

  3. Navigate to Port Forwarding settings (may be under "NAT", "Virtual Servers", or "Gaming")

  4. Create port forwarding rules for each game server:

    • External Port: Game port (e.g., 34197)
    • Internal IP: Your server's local IP
    • Internal Port: Same as external port
    • Protocol: UDP or TCP (see table above)
  5. Find your public IP address:

    curl -s ifconfig.me
  6. Share your public IP with friends to connect

Security Considerations

  • Only forward ports for games you actively use
  • Consider using a dynamic DNS service if your public IP changes frequently
  • The game server firewall (UFW) already restricts access to only the necessary ports
  • For additional security, some games support password protection (configured in inventory.yml)

About

Homelab-ready game server infrastructure. Deploy and manage Factorio, Palworld, and Terraria servers with Ansible, Terraform, and a Preact status dashboard.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published