Giter VIP home page Giter VIP logo

factorio_as_a_service's Introduction

Factorio As A Service

This python script has 2 major purposes: create easily a systemd service for factorio on Linux and updating the game automatically.

Requirements

  • Linux supporting systemd
  • Sudo installed
  • python >= 3.4
  • git

How to download it ?

Go to the desired directory for the installation and use this command:

git clone https://github.com/Pirheas/factorio_as_a_service.git

How to use it ?

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

1. Configuration file

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 a data 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:

mkdir /etc/faas
cp ./config.ini /etc/faas/config.ini

Alternatively, you can run the command using the -C parameter:

./faas.py -C ./config.ini -h

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

2. Download/Update the server

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
2.1

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, ...

3. Create the Factorio Service

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

3.1 Verify and control your 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

4 Automatic updates with cron

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.

FAQ

What does this tool exactly ?

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.

Other tools already exist, why create a new one ?

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

Do I need to stop the server before starting the update command ?

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.

It doesn't work

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 in config.ini)
  • Always execute faas.py with this user (except when using -c flag since it requires root)

Are my saved game safe ?

Normally yes. Updates should not delete your saved games. But it's always safer to have backups.

Can I revert to a previous version ?

Not yet. You can do it manually and still run the service creation command though.

I used to specify the port as a parameter. It's not possible anymore. How do I do ?

Indeed, you must now specify parameters (such as the port) in the file (Game directory)/config/config.ini

I have multiple factorio servers running on my server. Can I still do that ?

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

factorio_as_a_service's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.