Skip to content

Instantly share code, notes, and snippets.

@nogweii
Last active March 27, 2016 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nogweii/13da41135c8ba73df1a9 to your computer and use it in GitHub Desktop.
Save nogweii/13da41135c8ba73df1a9 to your computer and use it in GitHub Desktop.
factorio server administration, on centos7

Installing

Go to http://www.factorio.com/download-headless/stable and download the latest stable. As of this writing, that would be 0.12.26

The headless server is a tarball of a (mostly?) statically-compiled server along with data. You will need to extract it and put it into a directory. Since this is a 3rd-party program, not managed by the package manager, I feel like /opt is a good choice.

tar xf factorio_headless_x64_0.12.26.tar.gz
sudo mv factorio /opt
sudo chown -R root:root /opt/factorio

Generating the map

Before starting and publishing your server, you need to generate the initial map. Nice and simple:

sudo /opt/factorio/bin/x64/factorio --create SAVE_NAME

This will create the map called SAVE_NAME.zip in /opt/factorio/saves. If you include a /, subdirectories will be made automatically for you. Useful to namespace a user's saves. However, autosaves will always be called _autosaveN.zip, so I'd guess if you're hosting multiple instances there could be conflicts.

Starting & managing it with SystemD

SystemD is the best init daemon for Linux, in my opinion. So here's a unit file to manage running instances:

[Unit]
Description=Factorio game server
Documentation=http://www.factorio.com/

[Service]
Type=simple
ExecStart=/opt/factorio/bin/x64/factorio --start-server=SAVE_NAME
User=root
WorkingDirectory=/opt/factorio/

[Install]
WantedBy=multi-user.target

This is a quick & lazy unit file, a better one could possibly be made. Otherwise, just edit the ExecStart line above to use the same SAVE_NAME as the one you generated earlier.

@nogweii
Copy link
Author

nogweii commented Mar 20, 2016

Just found out about https://github.com/trast/factorio-screenshots, the server is brand new so it won't be interesting just yet, but I'll probably update this later on.

@nogweii
Copy link
Author

nogweii commented Mar 20, 2016

Trying to create a new map after creating the first one caused some problems. I'm guessing, from looking at the logs, the server expected some files that don't apply in a brand new map. Moving /opt/factorio/temp/mp-download.zip out of the way (or deleting it) seems to allow clients to connect again.

This implies that running multiple instances would require isolated game server directories at the moment.

@nogweii
Copy link
Author

nogweii commented Mar 20, 2016

I hope you're using a firewall! Here's how to ensure your friends can connect to your server, if you're using firewalld:

Make /etc/firewalld/services/factorio.xml to describe the service.

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Factorio game server</short>
  <description>Factorio is a game all about automation. There is a huge tech tree, but in order to reach all of it, you need to build machines that build machines. This is the available headless dedicated server. See also, factorio.service</description>
  <port protocol="udp" port="34197"/>
</service>

Then reload the firewall daemon so it knows about the new XML file (firewall-cmd --reload) and enable the service, to allow remote connections (firewall-cmd --add-service=factorio).

@nogweii
Copy link
Author

nogweii commented Mar 27, 2016

Accidentally lost the server, but at least one of the my friends had a copy of the map saved on their hard drive. Since the server & client share the same format, it was as simple as copying the .zip from their computer to the server. While rebuilding the server, I didn't run --create (no need to, the map has already been generated) and instead manually created the saves directory and put the zip (renamed from _autosave1.zip) and placed it within.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment