Of Factorio

December 12, 2018 in linux ‐ 2 min read

In my free time, amongst other things, I like to play a round of Factorio. In a nutshell Factorio is a game centered around automating production.

I think this Video explains the concept of the game quite well.

https://www.youtube.com/watch?v=KVvXv1Z6EY8

This game can be played by multiple players on a server. There is a nice Docker Container for Factorio that allows you to have your own server up and running in no time.

 

Unfortunately there is no easy way to allow other players uploading maps to the server. So I came up with a solution using nextcloud.

What you need:

  • A Docker Host that is running the dtandersen/factorio container
  • A resource (like a nextcloud) that you can check a file from, download a savegame from and share with others

The Idea:

  • The Docker Host is running a script (see below) every minute

Add the following line to the /etc/crontab and use the path were you dropped that script.

* * * * * root /path/to/script.sh

  • This script checks the content of a textfile at a resource of your choice using ssh
  • In case the text file does not contain a 1, nothing happens
  • In case the file does contain a 1 the script will be run

The script:

  • Stops docker
  • Moves the currently running map in a backup directory
  • Then deletes the current savegame
  • Connects to a ressource, downloads *.zip and places them in the savegame directory
  • Changes the owner of the savegame so the docker container can work with it
  • Restarts docker
  • Writes into a logfile at the ressource

Directories:

  • The savegame directorz, mounted by the container is  /opt/factorio/save

You will have to change the script by hand, and generate the ssh keys. It is not pretty but it does work.

image

 

Cheers, Ori

 

#!/bin/bash factorio=$(ssh root@IP ‘cat path/to/Checkme.txt’)

if (echo $factorio | grep -q “1”) then service docker stop cp /opt/factorio/saves/save.zip /opt/factorio/backup_save/save.zip rm -rf /opt/factorio/saves/* scp root@IP:/path/to/savegame/\*.zip /opt/factorio/saves/. chown -R 845:845 /opt/factorio/saves

service docker start

ssh root@192.168.122.79 ’echo “0” > path/to/Checkme.txt’ ssh root@192.168.122.79 ’echo “Server rebooted at $(date +\%d-\%m-\%Y-\%H-\%M-\%S)” » path/to/RebootLog.txt’ factorio=0 else echo “DEBUG ME SEMPAI” fi