๐Ÿ› ๏ธ Factorio Headless Server Setup on Linux (Systemd)

๐Ÿ“ฆ 1. Create a User for the Server

sudo useradd -m -r -s /bin/bash factorio

This creates a non-login system user named factorio.


๐Ÿ“ 2. Set Up Directory and Download Server

sudo mkdir -p /opt/factorio
sudo chown factorio:factorio /opt/factorio
cd /opt/factorio

Download the latest headless server from Factorioโ€™s website:

wget https://www.factorio.com/get-download/latest/headless/linux64 -O factorio_headless.tar.xz

Or upload form you computer to server:

scp factorio.x.y.tar.xy <user>@<server ip or hostname>:.

Extract it:

tar -xvf factorio_headless.tar.xz
rm factorio_headless.tar.xz

This extracts into a directory like factorio. You can rename it or keep it as is:

mv factorio/* . && rmdir factorio

๐Ÿงช 3. Run the Server Once to Generate Files

Switch to the factorio user and run the server once to create default files:

sudo -u factorio /opt/factorio/bin/x64/factorio --create /opt/factorio/saves/base-game.zip

This creates a basic save file.


โš™๏ธ 4. Configure the Server

Edit /opt/factorio/data/server-settings.json to adjust name, description, visibility, etc.

You can also copy the example:

cp /opt/factorio/data/server-settings.example.json /opt/factorio/data/server-settings.json

Edit it with:

sudo -u factorio nano /opt/factorio/data/server-settings.json

๐Ÿš€ 5. Create the Start Script

Create a simple script to launch the server:

sudo nano /opt/factorio/start-base

Paste this in:

#!/bin/bash
cd /opt/factorio
exec ./bin/x64/factorio \
  --start-server ./saves/base-game.zip \
  --server-settings ./data/server-settings.json

Then make it executable:

sudo chmod +x /opt/factorio/start-base

๐Ÿ”ง 6. Create a systemd Service

Create the service file:

sudo nano /etc/systemd/system/factorio.service

Paste the following:

[Unit]
Description=Factorio Headless Server
After=network.target

[Service]
User=factorio
Group=factorio
WorkingDirectory=/opt/factorio
ExecStart=/opt/factorio/start-base
Restart=on-failure
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

๐Ÿ”„ 7. Enable and Start the Service

Reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl enable factorio
sudo systemctl start factorio

๐Ÿ“‹ 8. Check Logs and Status

To check the status:

sudo systemctl status factorio

To follow the server logs:

journalctl -u factorio -f -o cat

๐Ÿงผ 9. Optional Cleanup

Delete the downloaded archive (if you havenโ€™t already):

rm /opt/factorio_headless.tar.xz