Headless Factorio System Service
Updated: May 28, 2020
I was working on cleaning up my Factorio admin script and decided to finally migrated the headless server into systemd.
This post will be more focused on the quick task of setting up systemd so we can automate the start/stop/restart functions of Factorio as a headless server. You can view the more manual process by following the GIST link at the bottom of the page and viewing the revisions of the current script.
Login with the Steam service account created in the Server Setup Guide for Steam Games.
Change directory to the "/etc/systemd/system" folder. We will create our service file here and update the text. You can use your favorite text editor but I like to use nano.
Paste, or type, out the details for your server to include the path to the factorio file. Here is an example of my factorio.service file. I use a service account called steam which is listed as the "User" and can also be seen in the path to the factorio server executable (/home/steam).
The executable and configuration is based off the game manual. You can get the details on how to generate this file from (using my paths): "/home/steam/factorio --help". In my example, I tell the server to use my current community save file (MegaBase4Realz.zip) and I specify the path to server-settings, server-whitelist and somewhere to output the logs from my console.
The server-settings file contains all of the information about the running server. The whitelist file is where I store all of the authorized Factorio logon names. The server in the above example is for community members only which is why we have the whitelist. Finally the console-log tells the service where to output the log files so I can keep an eye on the running services.
Once you have everything formatted, and entered, correctly. You can save with CTRL+O (the letter), and hit enter to use the current name. Then CTRL+X to quit out of nano and return to the cli. The last step in the setup is to tell the system to refresh systemd which allows the server to recognize the update service file: "systemctl daemon-reload"
The server should now see our service. Try starting the service and viewing the status to determine if you did it correctly.
You should now have a functioning Factorio Headless server service. Take a look at the below script if you need some ideas on how to use them in some maintenance scripts. I will do a more through walk through of the below script next time!