This python script has 2 major purposes: create easily a systemd service for factorio on Linux and updating the game automatically.
- Linux supporting systemd
- Sudo installed
- python >= 3.4
- git
Go to the desired directory for the installation and use this command:
git clone https://github.com/Pirheas/factorio_as_a_service.git
First, I recommend to create a new user who will own both this script and the whole game directory.
Use the -v
flag for verbose. It may be useful for debugging
Type this command for help:
$ python3 ./faas.py -h
Edit the configuration file (config.ini
)
You will have to configure at least these fields:
- factorio-path : Path of the factorio directory (it should contains a
bin
and adata
directory) - save-path : Path of the saved game (zip file). If you don't have created it yet, consider reading this tuto
- user : The user who will execute the factorio server (choose an existing linux user,
root
is a bad idea but will works)
By default the script will be looking for the file in: /etc/faas/config.ini
. You need to create this folder manually:
sudo mkdir /etc/faas
cp ./config.ini /etc/faas/config.ini
If there is no file at /etc/faas/config.ini
it will try to use the config file in the same directory ./config.ini
Alternatively, you can run the command using the -C
parameter to specify yourself the path of the config file:
python3 ./faas.py -C /home/me/myfaasconfig/config.ini -i
NB: When you are using a relative path, the working directory will always be the directory that contains
faas.py
. Please consider using absolute path
Once the destination is defined in the configuration file, execute the update command. It will perform an update to the latest version (even if the directory is empty)
$ python3 ./faas.py -u
If it's not done yet, create your server save file
and specify its path in config.ini
Be sure that the user who is configured to launch the server has all permissions needed. Ex: Execute the binary, write in the save file, ...
Simply run this command as root
# python3 ./faas.py -c
If you change your configuration file, run this command to apply the modifications to the service
Check the status of your service via:
$ systemctl status factorio
Start and stop the server with:
$ sudo systemctl start factorio
$ sudo systemctl stop factorio
The script has been specially designed to be easily usable with crontab. Once you are sure everyting is OOK (service is up and running), you can create new cron to automate the update.
Use this command to open the list of crontab (warning, execute it as the right user):
crontab -e
If you want to (checking) update every night, you can do add this line:
30 6 * * * /path/to/faas.py -u
If you want it every hours with logs:
0 * * * * /path/to/faas.py -u >> /path/to/logs.txt 2>&1
Validate and you're done.
The execution of the cron will not stop your server if there is no update. If an update is applied, the server will be stopped during the installation and directly restarted after.
Basically, it has two goals: updating the server and create a systemd service to launch the server process.
The update server command can easily be configured with a cron. This way, it can be updated automatically.
None allow to both update and configure the server as a (systemd) service. Plus this tool automate a lot of things and require a minimum configuration (3 fields only). Last but no least, with the verbose option, the problems are really well explained and it's easy to find what's wrong in case of failure
No, the update command will stop the server itself only if a new version is available. It will also restart the serve once the update is complete.
Hey, that's not a question! Most likely, it's a file permission problem. Be sure the user configured to be owner of the process has the right to write and execute files in factorio directory.
In order to avoid permission issues, I advice you to create a factorio
user (whatever the name) that will:
- Own the game directory
- Own
factorio_as_a_service
directory - Be responsible of the crontab
- Be the owner of the server process (field
user
inconfig.ini
) - Always execute
faas.py
with this user (except when using -c flag since it requires root)
While extracting data during an update, I encounter an 'Operation not permitted'. What's the problem ?
Once again, it's a permission problem. Be sure to have the write permission on all factorio files. If not, use a chmod -R
to be sure the desired user is the owner of factorio directory.
Normally yes. Updates should not delete your saved games. But it's always safer to have backups.
Not yet. You can do it manually and still run the service creation command though.
Indeed, you must now specify parameters (such as the port) in the file (Game directory)/config/config.ini
Yes, but you'll need 2 different game install and 2 times factorio_as_a_service (one for each installed game).
You must also change theservice-name
for at least one of the faas.py in its config.ini
file