A factorio init script in bash
If you find yourself wondering why stuff is not working the way you expect:
tail -f /opt/factorio/factorio-current.log
in a separate sessionTry running the same commands as the factorio user (/opt/factorio-init/factorio invocation
will tell you what the factorio user tries to run at start)
/opt/factorio-init/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
Create a directory where you want to store this script along with configuration. (either copy-paste the files or clone from github):
cd '/opt'
git clone https://github.com/Bisa/factorio-init.git
Rename or copy config.example
to config
and modify the values within according to your setup.
Unless you need files from the extras
dir (check the below sections) you can safely remove it.
The config has options for declaring an alternate glibc root. The user millisa over on the factorio forums has created a wonderful guide to follow on creating this alternate glibc root (side by side).
If you don't have Factorio installed already, use the install
command:
/opt/factorio-init/factorio install # see help for options
The installation routine creates Factorio's config.ini
automatically.
If you previously ran Factorio without this script, the existing config.ini
should work fine.
# either symlink:
ln -s /opt/factorio-init/extras/bash_autocomplete /etc/bash_completion.d/factorio
# or source:
echo "source /opt/factorio-init/extras/bash_autocomplete" >> ~/.bashrc
# then ensure factorio-init is added to your PATH, ie by:
ln -s /opt/factorio-init/factorio /usr/local/bin/factorio
# restart your shell to verify that it worked
cp /opt/factorio-init/extras/factorio.service.example /etc/systemd/system/factorio.service
# Edit the service file to suit your environment then reload systemd
systemctl daemon-reload
systemctl start factorio
systemctl status -l factorio
# Remember to enable the service at startup if you want that:
systemctl enable factorio
Note that systemd won't be able to keep track of the server process if you use this script to restart during updates. Use the config option UPDATE_PREVENT_RESTART=1
and implement your own stop/start logic to work around this.
ln -s /opt/factorio-init/factorio /etc/init.d/factorio
# Make the script executable:
chmod +x /opt/factorio-init/factorio
# Try it out:
service factorio help
# Do not forget to enable the service at boot if you want that.
When contributing to this repo, please ensure your contribution is covered by at least one test in test/factorio.bats
or the very least: do not create pull requests with failing tests, thank you.
Testing is done using bats-core, bats-assert and bats-support.
@test "DEBUG=1 produces output" {
# To access functions within ./factorio, source it then use the run command:
source ./factorio
export DEBUG=1
run debug "TEST"
# use the various asserts from bats-assert
assert_output "DEBUG: TEST"
}
git submodule init
git submodule update
git config --local core.hooksPath extras/.githooks
The extras/.githooks/pre-push
will run shellcheck, local tests as well as docker tests with and without resources.
docker build --build-arg ubuntu_version=20.04 \
--build-arg factorio_version=1.1.61 \
--tag ubuntu-finit:latest - < extras/docker/Dockerfile.ubuntu
docker build --build-arg centos_version=centos8 \
--build-arg factorio_version=1.1.61 \
--tag centos-finit:latest - < extras/docker/Dockerfile.centos
Adding --target no-test-resources
to the build command will avoid downloading test resources online but it will also skip tests that rely on the resources(!)
docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init ubuntu-finit:latest extras/test
docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init centos-finit:latest extras/test
Please note that some tests will be skipped unless you run them with the docker image or via .githooks, but running them manually is a quick way to get started.
./extras/test/libs/bats-core/bin/bats extras/test
Using parallel, adding --jobs 10
to the above (adjust the number accordingly) will allow you to execute more tests in parallel and in turn possibly decrease the total time required to complete the run.
You are all a great source of motivation, thank you.
This code is realeased with the MIT license, see the LICENSE file.