Factorio-multienv-ctl is a fork of factorio-init, which allows you to have multiple environments of factorio servers on the same machine. It also includes a Debian package which will set up both the factorio server binaries and factorio-multienv-ctl.
- Install this package (see prepared Debian package section).
- Run
factorio new-game somenameforyourgame
or upload a existing savegame to/var/factorio/instances/default/saves/
- Run
factorio start
orsystemctl start factorio@default
- Optionally: run on system boot:
systemctl enable factorio@default
- To use another environment:
- run
FENV=myenvname factorio new-game somenameforyourgame
- run
FENV=myenvname factorio start
orsystemctl start factorio@myenvname
- run
You can find prebuilt packages for Debian 8 at http://repo.factoriommo.org/
These have been known to work on Ubuntu 16.04 and 16.10 as well, they might also work for other apt based distros running systemd as init.
# Add gpg pubkey
curl http://repo.factoriommo.org/apt.gpg | apt-key add -
# or if you prefer wget instead of curl (installed by default on Ubuntu)
wget -O - http://repo.factoriommo.org/apt.gpg | apt-key add -
# Add deb repo entry
echo "deb http://repo.factoriommo.org/ jessie main" > /etc/apt/sources.list.d/factoriommo.list
# Update apt lists
apt-get update
# Install package
apt-get install factorio-multienv-ctl
Factorio-multienv-ctl uses the FENV
environment variable. This defaults to default
.
To explain what factorio-multienv-ctl does, here is an overview of what paths are used,
and what can be customized.
-
Core game files are always installed to
/opt/factorio/factorio/
. -
The Debian package will create
/var/factorio/mods/
, in which you can store shared modpacks. More on this later. -
Every instance will have its write-data location set to
/var/factorio/instance/{name}/
, where{name}
defaults todefault
. This folder contains bothsaves
andmods
folders for this instance to use. Theserver.out
andserver.pid
files will also be put here. Factorio-multienv-ctl automatically overwritesconfig.ini
with the correct write-data entry. -
You can set the environment by setting
FENV
before usingfactorio
command, which is the factorio-multienv-ctl script, not the actual factorio server binary. -
For auto-startup of factorio servers, you can use the parametrized systemd service. This allows you to enable/start a server like this:
systemctl start factorio@{name}
, where{name}
is the name of the environment. There is no default, you will need to manually runsystemctl start factorio@default
to enable the default server.
All configuration that factorio-multienv-ctl recognizes should live in /etc/factorio
.
Factorio-multienv-ctl will load and try to inherit customizations in the correct order.
This however is not done for json files, those completely overwrite the defaults,
so ensure your customized server-settings.json contains all values.
Required configfiles:
- config.ini
- server-settings.json
Optionally you may create map-gen-settings.json
and/or init.conf
(see below),
and their paramatric versions.
You can create overrides for specific instances by putting them in /etc/factorio/$FENV/
.
For instance FENV=asdf
to override server-settings.json
you create
/etc/factorio/asdf/server-settings.json
.
Note that /etc/factorio/asdf/init.conf
inherits from /etc/factorio/init.conf
if it exists,
and the json files don't.
If you create /etc/factorio/asdf/config.ini
,
it will be copied to /var/factorio/instances/asdf/config.ini
,
and the write_dir
will be overwritten in the latter on every start.
The following values all have sane defaults, but can be customized. In theory you can override every variable used in the main script, but it's recommended you don't. We divide the environment variable sin 2 categories: important and details
Alter factorio main metadata
Name | Default Value | Description |
---|---|---|
FENV |
default | name fo the environment representing the factorio server instance |
Debug |
undefined | enable bass tracing to help debugging. If non-zero, we will output additional information when running the script. |
EXTRA_BINARGS |
--start-server-load-latest |
extra command line arguments you can feed to factorio executable |
FUSERNAME |
factorio | Username used to run the factorio program |
USERGROUP |
factorio | User group used to run factorio program |
FACTORIO_PATH |
/opt/factorio/factorio | Path to a directory where the subpath /bin/x64/factorio can be resolved soundly |
SAVELOG |
0 | If non-zero, we will delete the previous log file before starting the service |
SERVER_PORT |
34197 | the port where the server instance will listen for new connections |
WRITE_DIR_BASE |
/var/factorio/instances |
Directory containing every factorio server data instance |
FCONF |
Either /etc/factorio/${FENV}/config.ini or, if non-existent, /etc/factorio/config.ini |
|
SERVER_SETTINGS |
Either /etc/factorio/${FENV}/server-settings.json or, if non-existent, /etc/factorio/server-settings.json |
|
MAPGEN_CONF |
Either /etc/factorio/${FENV}/map-gen-settings.json or, if non-existent, /etc/factorio/map-gen-settings.json |
|
MOD_DIRECTORY |
"" | If existent, the folder where we will pass to factorio containing the mod to load on the particular server instance. Needs to be writeable for the factorio user. |
Alter support metadata of the project
Name | Default Value | Description |
---|---|---|
PIDFILE_NAME |
server.pid | name of the file containing the server process id |
WRITE_DIR |
/var/factorio/instances/${FENV} |
directory where the data of the factorio server instance (specific to the given environment) will be saved. |
CMDOUT_FILENAME |
factorio.log | File where we will write logs. If CMDOUT is left the default one, the file is placed under WRITE_DIR |
FIFO |
server.fifo | file representing the communication channel from/to factorio stdin/stdout. If CMDOUT is left the default one, the file is placed under WRITE_DIR |
PIDFILE |
$WRITE_DIR/server.pid |
file containing the server process id. If CMDOUT is left the default one, the file is placed under WRITE_DIR |
SERVER_BIND |
"" |
To customize the behavior of factorio-multienv-cli
, you can create a bash script like this one:
#!/usr/bin/env bash
EXTRA_BINARGS="--start-server-load-latest" # you should use `factorio load-save` with this.
RCON_PORT=""
RCON_PASSWORD=""
SAVELOG=0
SERVER_BIND=""
SERVER_PORT=34197
MOD_DIRECTORY="" # eg: /var/factorio/mods/ArumbaMegaModPack
USERGROUP=factorio
FUSERNAME=factorio
DEBUG=0
factorio-multienv-cli newgame newAwesomeGame
If you find yourself wondering why stuff is not working the way you expect:
- Check the logs, you can use
factorio log
andfactorio log --tail
, also parametric:FENV=asdf factorio log
. - Enable debugging in the config (by setting
DEBUG
variable to 1) and/or: - Try running the same commands as the factorio user (
factorio invocation
will tell you what the factorio user tries to run at start)
$ factorio invocation
# Run this as the factorio user, example:
$ sudo -u factorio 'whatever invocation gave you'
# You should see some output in your terminal here, hopefully giving
# you a hint of what is going wrong
Is included with the Debian package, and will activate if you
install bash-completion
package and enable system-wide completion.
The install
and update
commands have been removed,
dependency on updater python script is also removed.
Also, the config and environment handling has been overhauled to accomodate for multiple environments.
Because the Debian package also creates /etc/server-settings.json and other default files,
dpkg
will track those and notify when a package update tries to overwrite customized versions.
You can move the default files out of the way to prevent this message during updates:
dpkg-divert --add --rename --divert /etc/factorio/.old-server-settings.json /etc/factorio/server-settings.json
You can copy .old-server-settings.json or create a customized server-settings.json afterwards.
Prerequisites: devscripts dpkg-dev debhelper debianutils bash-completion
Then run debuild
in the folder containing the debian
folder (the same one as this readme is in.)
Afterwards, you will find your .deb files one directory up.
factorio-multienv-ctl
is based on factorio-init
, see https://github.com/Bisa/factorio-init for details.
This code is realeased under the MIT license, see the LICENSE file.