GithubHelp home page GithubHelp logo

factorio-init's Introduction

Factorio Init

A factorio init script in bash

Requirements

Debugging

If you find yourself wondering why stuff is not working the way you expect:

  • Check the logs, I suggest you tail -f /opt/factorio/factorio-current.log in a separate session
  • Enable debugging in the config and/or:
  • Try 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

Install

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

Notes for users with an OS that has a older glibc version

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

First-run

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

Autocompletion

  • Copy/symlink or source the bash_autocompletion file
  • Ensure the factorio script is in your path
# 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

Systemd

  • Copy the example service, adjust & reload
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
  • Verify that the server starts
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.

SysvInit

  • Symlink the init script:
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.

Contributing

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.

Test the code

Testing is done using bats-core, bats-assert and bats-support.

  • Write a test case, example:
@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"
}
  • init and update the submodules (if you did not already)
git submodule init
git submodule update
  • Then run the tests, see the following sections:

With .githooks

  • Set the hooks path to our .githooks directory
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.

With Docker

  • Build the docker image(s) (a slightly modified ubuntu/centos)
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(!)

  • Then run the image, mounting the current directory and removing the container once it's done
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

Manually

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.

  • run the tests
./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.

Thank You

  • To all who find this script useful in one way or the other
  • A big thank you to Wube for making Factorio
  • A special thanks to NoPantsMcDance, Oxyd, HanziQ, TheFactorioCube and all other frequent users of the #factorio channel @ esper.net
  • Thank you to Salzig for pointing me in the right direction when it comes to input redirection
  • At last, but not least; Thank you to all contributors and users posting issues in my github project or on the factorio forums

You are all a great source of motivation, thank you.

License

This code is realeased with the MIT license, see the LICENSE file.

factorio-init's People

Contributors

abilbaotm avatar arendjanh avatar bioxz avatar bisa avatar bluepython508 avatar descention avatar dshemetov avatar einpinsel avatar eliihen avatar glektarssza avatar jadoc avatar jhawkwind avatar jshumaker avatar max-leopold avatar meiamsome avatar n-coder avatar nbugrov avatar nrdobie avatar r41d avatar rmbleeker avatar seyfahni avatar shanemcc avatar stuartjsquires avatar tantrisse avatar the-eater avatar tmzasz avatar tomix1024 avatar vnznznz avatar windsinger1985 avatar zack-shoylev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

factorio-init's Issues

service factorio screen

I used the "service factorio screen" command very often, to see whats going on. You seem to have removed it. Whats the new way to reach the console output?

0.14.12 Settings Changes Break Start Script

Running factorio-init/factorio start with 0.14.12 experimental version gave me this error:

Unable to start Factorio
Could not start Factorio

I ran `factorio-init/factorio invocation' and saw that the script was trying to run this command:

/opt/factorio/bin/x64/factorio --config /opt/factorio/config/config.ini --port 34197 --start-server-load-latest --server-settings /opt/factorio/data/server-settings.json --autosave-interval 10 --autosave-slots 3 --allow-commands admins-only

Reading the changelog for 0.14.12, I saw that the autosave-interval and autosave-slots (as well as allow_commands, afk_autokick_interval, and auto_pause) are now settable only in server-settings. I think this is what is causing the issue.

Permission?

I installed the headless server from factorio, followed the guide, and it runs smoothly, added user factorio:factorio and chowned the folder to factorio:factorio

it works quite good... but when i try to start via the factorio-init, it gives this:

DEBUG: Determining WRITE_DIR based on /root/factorio/config/config.ini, IF you edited write-data from the default, this probably fails
DEBUG: write path: /root/factorio/bin/x64/../..
Check Permissions. Cannot write to /root/factorio/bin/x64/../..

Here is the invocation:

DEBUG: Determining WRITE_DIR based on /root/factorio/config/config.ini, IF you edited write-data from the default, this probably fails
DEBUG: write path: /root/factorio/bin/x64/../..
/root/factorio/bin/x64/factorio --config /root/factorio/config/config.ini --port 34197 --start-server-load-latest --server-settings /root/factorio/online_show.config.json

everything is nicelly configured, and the paths are corrects, any help will be apreciated.

0.14.19 Settings Changes Break Start Script

It looks like the moved several more of the command line args have been moved into the json. Once again causing the script to fail to load.

It looks to be the auto save frequency and slots

act on chat commands?

with 0.13 introducing logged chat it's possible to parse and act on chat commands

update sorts updates incorrectly

When applying updates, update does not numerically sort version numbers;

New version core-linux_headless64 0.13.18.
Wrote /tmp/factorio-update/core-linux_headless64-0.12.35-0.13.0-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.12.
35-0.13.0-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.0-0.13.1-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.0
-0.13.1-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.1-0.13.2-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.1
-0.13.2-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.2-0.13.3-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.2
-0.13.3-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.3-0.13.4-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.3
-0.13.4-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.4-0.13.5-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.4
-0.13.5-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.5-0.13.6-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.5
-0.13.6-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.6-0.13.7-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.6
-0.13.7-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.7-0.13.8-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.7
-0.13.8-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.8-0.13.9-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.8
-0.13.9-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.9-0.13.10-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13.
9-0.13.10-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.10-0.13.11-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.10-0.13.11-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.11-0.13.12-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.11-0.13.12-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.12-0.13.13-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.12-0.13.13-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.13-0.13.14-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.13-0.13.14-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.14-0.13.15-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.14-0.13.15-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.15-0.13.16-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.15-0.13.16-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.16-0.13.17-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.16-0.13.17-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.13.17-0.13.18-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.13
.17-0.13.18-update.zip`
Still not shut down, waiting a while longer...
Factorio is now shut down.
Applying /tmp/factorio-update/core-linux_headless64-0.12.35-0.13.0-update.zip ...
Applying /tmp/factorio-update/core-linux_headless64-0.13.0-0.13.1-update.zip ...
Applying /tmp/factorio-update/core-linux_headless64-0.13.10-0.13.11-update.zip ...
   0.000 2016-08-26 18:10:54; Factorio 0.13.1 (Build 22864, linux64, headless)
   0.169 Operating system: Linux (Ubuntu 14.04)
   0.169 Program arguments: "/home/factorio/factorio/bin/x64/factorio" "--apply-update" "/tmp/factorio-update/core-linux_headless64-0.13.10-0.13.11-update.zip"
   0.169 Read data path: /home/factorio/factorio/data
   0.169 Write data path: /home/factorio/factorio
   0.169 Binaries path: /home/factorio/factorio/bin
   0.255 Running in headless mode
   0.259 Loading mod core 0.0.0 (data.lua)
   0.281 Loading mod base 0.13.1 (data.lua)
   0.804 Checksum for core: 1399339455
   0.804 Checksum for mod base: 2679425721
   1.946 Custom inputs active: 0
   1.947 Factorio initialised
   1.948 Info Updater.cpp:390: Applying update /tmp/factorio-update/core-linux_headless64-0.13.10-0.13.11-update.zip
   3.998 Error Util.cpp:57: File /home/factorio/factorio/bin/x64/factorio has unexpected content
   4.027 Goodbye

Error! Failed to apply update

Lots of errors on ubuntu 15.10 server. Not sure if I'm a noob or if its incompatible with something.

Factorio launches in the background, but factorio-init doesn't recognise it. To stop it I have to 'killall factorio'. Is it an issue with ubuntu or me?

factorio@orange:/opt/factorio/mods$ factorio start
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: last modified save: /opt/factorio/saves/factorio-init-save.zip
DEBUG LOG: using existing factorio-init-save.zip
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
Still not running, waiting a while longer...
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
Failed to start, aborting.

Save on stop?

Hello,
I updated my Server from 0.12.28 to 0.12.29 via your script. Now it seem like I have lost 3-5 minutes gameplay time (no desaster). I know all players should disable auto save and the server does the auto save. I set this to 3 minutes. When the last server-auto-save is a few minutes ago and all player quit, does it ever do an auto save again? I then did stop the server and started the update. When I reconnected 2-4 new assembler buildings where missing. Does the server/script save when I stop it?

Add proxy support

Hi,

my server need a proxy for outgoing http request. Do you can add a proxy parameter?

Cheers!

Why abandon systemd?

Why the systemd was abandoned? I think it was good and also the output from it was quite nice.

Now status is only - Factorio is running, nothing more. 👎

Also it's no longer running as service ?

Binary arguments

I have to look into adding your own custom arguments to the binary (mostly to allow for easy "manual" updates to this script)

Recent 1.12.7 introduced
--disallow-commands and --peer-to-peer

Service cannot be started if config/config.ini is not present

This one stumped me for a while, basically I hadn't run the factorio server before and it hadn't generated the default config yet.
If the server is started with --config PATH then that config must exist otherwise it creates an error. That error by the way isnt getting shown because it's created in the screen.

Best to check if the config exists, if not warn the user who is executing the script and tell them to run the server once to have it create a default config

EXTRA_BINARGS are forced

Attempting to start a Factorio server on Ubuntu 14.04.3 without EXTRA_BINARGS doesn't seem to work. I tried both using an empty string and removing it from INVOCATION, neither of which worked.

Debug log when EXTRA_BINARGS is an empty string

factorio@xxxxxxxxxx:/home/ubuntu$ service factorio restart
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"
No running server, starting it...
DEBUG LOG: last modified save: /opt/factorio/saves/factorio-init-save.zip
DEBUG LOG: using existing factorio-init-save.zip
DEBUG LOG: could not find a pid for binary: "/opt/factorio/bin/x64/factorio"

Debug log when removed from INVOCATION

factorio@xxxxxxxxxx:/home/ubuntu$ service factorio restart
DEBUG LOG: found pid: 1635
1983
28344
28797
28924
/etc/init.d/factorio: line 123: [: too many arguments
/etc/init.d/factorio: line 125: [: too many arguments
No running server, starting it...
DEBUG LOG: last modified save: /opt/factorio/saves/factorio-init-save.zip
DEBUG LOG: using existing factorio-init-save.zip
DEBUG LOG: found pid: 1635
1983
28344
28797
28924
29068

This output continued for a while before it quit.

server-settings.json missing

root@mc:/opt# service factorio update
Could not find factorio server settings file: /opt/factorio/data/server-settings.json
Update your config and point SERVER_SETTINGS to a modified version of data/server-settings.example.json

I just revived my old Factorio 0.12.30 headless server to update it to 0.13.x
To make things easy, I first updated your init-script (git pull) and then tried to update my "old" Factorio installation "service factorio update". But that only gave me the above error message. I assume that file is new with 0.13.x ? If so, how would be the correct update path? Can't I use your script together with the update in this case?

Permission error

Hello,

I'm getting the following message when doing "service factorio start":
"Check Permissions. Cannot Write to /opt/factorio-init/Factorio.pid. Correct the permission and then execute /etc/init.d/factorio status"
I've done chmod 777 and have tried different groups with chown and using -R for the files inside (since I can't go in the directory because it isn't one (?)).

I'm still fairly new to using ssh and might have made a dumb mistake. If so, sorry.

Thanks in advance for answering.

`tail` is not terminated when service exits due to a failed start

I just updated to the latest master (as of time of writing) and am tinkering with a few things in the invocation. I've noticed that the tail command is not terminated along with the Factorio server when the server terminates abnormally (eg: missing save file).

I'm unsure if this appears in other situations, but this is where I've observed it.

dmulligan@dmulligan /opt/factorio-init [master]±% sudo service factorio start                                                                                                                                  !3658
dmulligan@dmulligan /opt/factorio-init [master]±% sudo service factorio status                                                                                                                                 !3659
● factorio.service - LSB: start and stop Factorio server
   Loaded: loaded (/etc/init.d/factorio)
   Active: active (running) since Mon 2016-09-12 16:56:16 EDT; 1s ago
  Process: 5186 ExecStart=/etc/init.d/factorio start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/factorio.service
           └─5208 tail -f /opt/factorio/bin/x64/../../server.fifo

Sep 12 16:56:16 dmulligan.ca su[5202]: + ??? root:factorio
Sep 12 16:56:16 dmulligan.ca su[5202]: pam_unix(su:session): session opened for user factorio by (uid=0)
Sep 12 16:56:16 dmulligan.ca su[5204]: Successful su for factorio by root
Sep 12 16:56:16 dmulligan.ca su[5204]: + ??? root:factorio
Sep 12 16:56:16 dmulligan.ca su[5204]: pam_unix(su:session): session opened for user factorio by (uid=0)
Sep 12 16:56:16 dmulligan.ca su[5206]: Successful su for factorio by root
Sep 12 16:56:16 dmulligan.ca su[5206]: + ??? root:factorio
Sep 12 16:56:16 dmulligan.ca su[5206]: pam_unix(su:session): session opened for user factorio by (uid=0)
Sep 12 16:56:16 dmulligan.ca factorio[5186]: Started Factorio, please see log for details
Sep 12 16:56:16 dmulligan.ca systemd[1]: Started LSB: start and stop Factorio server.
dmulligan@dmulligan /opt/factorio-init [master]±% sudo service factorio stop                                                                                                                                   !3660
dmulligan@dmulligan /opt/factorio-init [master]±% sudo service factorio status                                                                                                                                 !3661
● factorio.service - LSB: start and stop Factorio server
   Loaded: loaded (/etc/init.d/factorio)
   Active: inactive (dead)

Sep 12 16:56:16 dmulligan.ca su[5204]: Successful su for factorio by root
Sep 12 16:56:16 dmulligan.ca su[5204]: + ??? root:factorio
Sep 12 16:56:16 dmulligan.ca su[5204]: pam_unix(su:session): session opened for user factorio by (uid=0)
Sep 12 16:56:16 dmulligan.ca su[5206]: Successful su for factorio by root
Sep 12 16:56:16 dmulligan.ca su[5206]: + ??? root:factorio
Sep 12 16:56:16 dmulligan.ca su[5206]: pam_unix(su:session): session opened for user factorio by (uid=0)
Sep 12 16:56:16 dmulligan.ca factorio[5186]: Started Factorio, please see log for details
Sep 12 16:56:16 dmulligan.ca systemd[1]: Started LSB: start and stop Factorio server.
Sep 12 16:56:20 dmulligan.ca systemd[1]: Stopping LSB: start and stop Factorio server...
Sep 12 16:56:20 dmulligan.ca factorio[5264]: No running server.
Sep 12 16:56:20 dmulligan.ca systemd[1]: Stopped LSB: start and stop Factorio server.
dmulligan@dmulligan /opt/factorio-init [master]±% sudo ps ax -F | grep factorio                                                                                                                                !3662
factorio  5208     1  0  1460   708   0 16:56 ?        S      0:00 tail -f /opt/factorio/bin/x64/../../server.fifo
dmullig+  5311  2978  0  3182  2008   0 16:56 pts/0    S+     0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn factorio

You can see that the server is not started successfully (no factorio process is spawned on start) but after stopping, the tail command remains active.

Alternative for systemd

I was able to follow your install instructions perfectly on a CentOS 7 box, but am now trying it on an Amazon Web Services LMI instance.

This does not have systemd, and so this step in your Readme does not work.

Can you advise of alternatives please, or does your script rely on systemd?

Simplification

I'm having second thoughts on parts of this script.

This issue serves to look at:

  • simplifying configuration
  • simplifying usage
  • generally reviewing the script to make it "simple"

Failed to start, aborting.

Hello,
today I tried your script on Ubuntu 14.04.4 LTS but without success. I always get the error, leaving open processes:
root@mc:/opt/factorio# service factorio start
Still not running, waiting a while longer...
Failed to start, aborting.
root@mc:/opt/factorio# ps -Af | grep fac
factorio 31747 1 0 13:56 ? 00:00:00 SCREEN -dmS factorio /opt/factorio/bin/x64/factorio --start-server factorio-init-save --autosave-interval 3 --autosave-slots 6 --latency-ms 250 --disallow-commands --peer-to-peer
factorio 31748 31747 0 13:56 pts/3 00:00:00 /opt/factorio/bin/x64/factorio --start-server factorio-init-save --autosave-interval 3 --autosave-slots 6 --latency-ms 250 --disallow-commands --peer-to-peer
root 31882 29998 0 13:58 pts/0 00:00:00 grep --color=auto fac
root@mc:/opt/factorio#
These open processes block the port so I have to kill them.
According to the log, everything is fine I assume:

root@mc:/opt/factorio# cat factorio-current.log
0.000 2016-03-18 13:56:34; Factorio 0.12.26 (Build 17762, linux64)
0.052 Operating system: Linux (Ubuntu 14.04)
0.052 Program arguments: "/opt/factorio/bin/x64/factorio" "--start-server" "factorio-init-save" "--autosave-interval" "3" "--autosave-slots" "6" "--latency-ms" "250" "--disallow-commands" "--peer-to-peer"
0.052 Read data path: /opt/factorio/data
0.052 Write data path: /opt/factorio
0.052 Binaries path: /opt/factorio/bin
0.061 Running in headless mode
0.064 Loading mod core 0.0.0 (data.lua)
0.066 Loading mod base 0.12.26 (data.lua)
0.427 Factorio initialised
0.428 Info Router.cpp:556: Router peerID(65535) shutting down.
0.428 Info Router.cpp:582: Router state -> Disconnected
0.428 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(-1) changing state from(Ready) to(PreparedToHostGame)
0.428 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(-1) changing state from(PreparedToHostGame) to(CreatingGame)
0.428 Loading map /opt/factorio/saves/factorio-init-save.zip
0.459 Info Scenario.cpp:124: Map version 0.12.26-0
0.709 Info MultiplayerManager.cpp:282: 0x7f5f997896e0, (nil)
0.709 Info PosixUDPSocket.cpp:34: Opening socket at port 65353
0.709 Info Router.cpp:582: Router state -> Connected
0.709 Info Synchronizer.cpp:54: NetworkTick(0) initialized Synchronizer local peer(0) latency(15).
0.709 Hosting game at port 65353, peerID 0, session magic 2122
0.709 Info MultiplayerManager.cpp:304: 0x7f5f997896e0, 0x7f5f997896e0
0.709 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(1235041) changing state from(CreatingGame) to(InGame)
0.709 Info NetworkInputHandler.cpp:40: mapTick(1235041) networkTick(0) initialized NetworkInputHandler local peer(0).
0.976 Info MultiplayerManager.cpp:1385: Received peer info for peer(0) username().
0.976 Info MultiplayerManager.cpp:1043: networkTick(15) mapTick(1235041) received stateChanged peerID(0) oldState(Ready) newState(CreatingGame)
0.976 Info MultiplayerManager.cpp:1043: networkTick(15) mapTick(1235041) received stateChanged peerID(0) oldState(CreatingGame) newState(InGame)
root@mc:/opt/factorio#

Du you have any idea why your script says the server doesn't start?

--latency-ms not longer supported in factorio 0.14 experimental

Launching the new experimental 0.14 with the script no longer works as it uses a no longer supported command line option which needs to be removed from the INVOCATION variable.

/opt/factorio/bin/x64/factorio --config /opt/factorio/config/config.ini --port 34197 --start-server-load-latest --server-settings /opt/factorio/data/server-settings.json --autosave-interval 5 --autosave-slots 24 --latency-ms 75
unrecognised option '--latency-ms'

(And thanks for the script, really helps running a server!)

Experimental

I use the python script to update the server. I found code in your script to download the experimental version too, but now how to invoke the update for experimental.

chatting from console

while chatting from the console is perfectly doable - I have not been able to avoid input and output mixing toghter and becoming garbled. Essentially this feels like a limitation of using a terminal for both input and output.

I'll just stick this here for now and use tail on the output file

Odd unhelpful error

Hi, sorry to open this as an issue but got an odd error.
I tried to get the server running via your script and hit a few bumps along the way but currently cant get past this one.
Unit factorio.service has begun starting up.
Jul 10 17:16:34 RMMD-MC-1 factorio[13734]: DEBUG: Determining WRITE_DIR based on /opt/factorio/config/config.ini, IF you edited write-data from the default, this probably fails
Jul 10 17:16:34 RMMD-MC-1 factorio[13734]: DEBUG: write path: /opt/factorio/bin/x64/../..
Jul 10 17:16:34 RMMD-MC-1 factorio[13734]: Unable to start vana
Jul 10 17:16:34 RMMD-MC-1 factorio[13734]: Could not start vana
Jul 10 17:16:34 RMMD-MC-1 systemd[1]: factorio.service: control process exited, code=exited status=1
Jul 10 17:16:34 RMMD-MC-1 systemd[1]: Failed to start Factorio Server.

This is running on a Centos7 x64 box, Below is my server config and also all the other configs i could think off
[root@RMMD-MC-1 factorio]# cat config/config.ini [path] read-data=__PATH__executable__/../../data write-data=__PATH__executable__/../.. [general] locale= [debug] show_fps=basic show_detailed_info=basic show_time_used_percent=basic show_multiplayer_waiting_icon=basic show_multiplayer_waiting_statistics=basic show_tile_grid=full show_collision_rectangles=detailed show_selection_rectangles=detailed show_paths=full show_next_waypoint_bb=full show_target=full show_unit_group_info=full show_unit_stuck_info=full show_last_path_detail=full show_path_cache=full show_path_cache_paths=full show_rail_paths=full show_rolling_stock_count=full show_rail_connections=detailed show_rail_segments=detailed show_rail_joints=detailed show_train_stop_point=detailed show_train_braking_distance=full show_train_signals=full show_network_connected_entities=detailed show_circuit_network_numbers=detailed show_energy_sources_networks=detailed show_active_state=detailed show_pollution_values=full show_active_entities_on_chunk_counts=full show_active_chunks=full show_enemy_expansion_candidate_chunks=full show_tile_variations=full show_raw_tile_transitions=never show_tile_correction_previews=never show_fluid_box_fluid_info=basic show_environment_sound_info=basic show_logistic_robot_targets=full [graphics] multisampling-level=0 lights-render-quality=0.200000003 fullscreen=false system-ui-scale=true custom-ui-scale=1 preferred-screen-index=255 show-smoke=true show-clouds=true show-inserter-shadows=true show-minimap=true show-pollution-on-minimap=true show-grid-when-paused=true show-inserter-arrows-when-detailed-info-is-on=false show-mining-drill-arrows-when-detailed-info-is-on=true light-entity-info-background=false force-opengl=false graphics-quality=normal v-sync=true screenshots_queue_size=10 screenshots_threads_count=1 max-texture-size=0 video-memory-usage=high disable-fma3=auto [sound] master_volume=0.600000024 ambient_volume=0.400000006 game_effects_volume=0.699999988 gui_effects_volume=0.699999988 walking_volume=0.300000012 environment_volume=0.449999988 alert_volume=0.550000012 audible_distance=40 environment_audible_distance=15 maximum_environment_sounds=15 active_gui_volume_modifier=1.29999995 active_gui_environment_volume_modifier=0.600000024 ambient_music_pause_mean_seconds=45 ambient_music_pause_variance_seconds=30 ambient_music_mode=interleave-main-tracks-with-interludes [other] tooltip_delay=0.0399999991 max_threads=4 show_tips_and_tricks=true autosort_inventory=true research_finished_stops_game=true use_item_groups=true use_item_subgroups=true output_console_delay=1200 autosave_interval=2 autosave_slots=3 enable_latency_hiding=true enable_new_mods=true port=34197 check_updates=true enable_experimental_updates=false proxy= verbose-logging=false

factorio-init config
http://pastebin.com/tRnTqW62
(gave up trying to deal with Githubs "code" for comments)

I can however run the server manually so at present it i running in a screen session.

Add Support for --headless

Currently, if you add the --headless flag, the check to see if the PID is running does not successfully return. I'm posting this to possibly plan to pull and fix in the next couple weeks, but I want to make sure it is actually an issue and I'm not just missing anything.

Problem with Systemd

Hi guy

I have a little problem when i use your init, i do all steps and i can use "service factorio start" but no "systemctl factorio start"

When i do systemctl show me this error:
unknown operation 'factorio'.

You know what is the problem?

Thanks you a lot ^^

Failed to connect to bus: No such file or directory

I get this message everytime I try to start the server with the service command. Any idea why this is happening?

After running "sudo systemctl list-units -t service --all" this is listed among other entries:
factorio.service loaded activating auto-restart

When I try to run that without sudo I get the same error.

I think I figured it out: I tried to start the service as a non root and that may have caused a problem

new server update

hello,

the latest server update changed the way that the headless server needs to be initialized. specifically some of the -- commands are pulled from the server-config file instead of through the command line. i just deleted the lines in the init script and it worked fine but people will not be able to launch without removing them

init script not working when EXTRA_BINARGS contains a whitespace at the end

I had to remove the "peer to peer" flag to make the server work for more than two players.
But I forgot a trailing whitespace - and suddenly the script didn't work anymore.
Even in the debug mode I spent an hour to find out that the whitespace was the mistake.
So could you add a comment there - and maybe remove the peer to peer flag also?

Factorio update fails if jumping multiple versions

factorio@linux:~$ rm -Rfv /tmp/factorio-update; sudo /etc/init.d/factorio update
removed ‘/tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip’
removed ‘/tmp/factorio-update/core-linux_headless64-0.12.26-0.12.27-update.zip’
removed directory: ‘/tmp/factorio-update’
Checking for updates...
New version core-linux_headless64 0.12.28.
Wrote /tmp/factorio-update/core-linux_headless64-0.12.26-0.12.27-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.12.26-0.12.27-update.zip`
Wrote /tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip, apply with `factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip`
Still not shut down, waiting a while longer...
Factorio is now shut down.
Applying /tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip ...
   0.000 2016-03-22 19:57:17; Factorio 0.12.26 (Build 17762, linux64)
   0.051 Operating system: Linux (Ubuntu 15.04)
   0.051 Program arguments: "/home/factorio/factorio/bin/x64/factorio" "--apply-update" "/tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip" 
   0.051 Read data path: /home/factorio/factorio/data
   0.051 Write data path: /home/factorio/factorio
   0.051 Binaries path: /home/factorio/factorio/bin
   0.062 Running in headless mode
   0.066 Loading mod core 0.0.0 (data.lua)
   0.069 Loading mod base 0.12.26 (data.lua)
   0.666 Factorio initialised
   0.667 Info Updater.cpp:390: Applying update /tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip
   1.072 Error Util.cpp:57: File /home/factorio/factorio/bin/x64/factorio has unexpected content
   1.087 Goodbye

Error! Failed to apply update
You can try to apply it manually with:
su factorio -c "/home/factorio/factorio/bin/x64/factorio --apply-update /tmp/factorio-update/core-linux_headless64-0.12.27-0.12.28-update.zip"
factorio@linux:~$

Log retention

Factorio as it is today stores 2 logs, one "current" and a previous log.

I've been wanting to add a feature that would rotate/retain logs on a server graceful shutdown to store more than 2 restarts' worth of logs.

Installation

I'm thinking of enhancing the installation process by using the freely provided headless tar package.

Options like "clean install" or "force update latest version" spring to mind, but without a readily accessible link to the "latest" version I'm not going to mess around with this - if you're watching this, feel free to show some love in https://forums.factorio.com/viewtopic.php?f=6&t=22210 to support this.

Does Not Apply Multiple Updates

Recently, I attempted to upgrade from 0.12.12 to 0.12.19 and the script only applies the first update file even though it downloaded all the update files necessary to update to the latest version. The workaround for this is to run 'service factorio update' until it reaches the latest version. This is inefficient since it repeatedly downloads all the files for update every time it is run.

EDIT: Just saw a similar issue closed about a week ago. Investigating fix and will close if issue is void.

Enhancement - More options.

I have added more options to the script which I though were missing.

  • new-game: creates a new blank map
  • save-game: save the current "factorio-init-save" with the given name.
  • list-saves: List all the saves in the saves folder. Can be used for input for load-save.

I've attached my script, you could probably do these a little better.

factorio.zip

factorio.service does not start in screen

The factorio.service does not start the factorio server in the prefered screen session.

All was set uped over the non-root user, the root-user was used to create the symlinks and to use the systemctl cmd.

Please fix this issue so that the server can run as service in a screen session (important)!

symlink is correctly working?

Thanks for creating nice script.

I think that I have to create actual file instead of symlink so that run systemctl enable factorio.service

It is the correct command?
cp /opt/factorio-init/factorio.service /etc/systemd/system/factorio.service

Factorio.pid

I'm sorry that I have to create that new issue but googling didn't lead to a solution, therefor I'm guessing this is a bug. I get this error when trying service factorio start

# systemctl status factorio.service
● factorio.service - (null)
   Loaded: loaded (/etc/init.d/factorio)
   Active: failed (Result: exit-code) since Tue 2016-04-12 18:15:57 CEST; 30s ago
  Process: 8851 ExecStart=/etc/init.d/factorio start (code=exited, status=1/FAILURE)

Apr 12 18:15:57 vmd10967.contabo.host su[8865]: pam_unix(su:session): session closed for user factorio
Apr 12 18:15:57 vmd10967.contabo.host factorio[8851]: Check Permissions. Cannot write to /opt/factorio/Factorio.pid. Correct the permissions and then excute: /etc/init.d/factorio status
Apr 12 18:15:57 vmd10967.contabo.host su[8870]: Successful su for factorio by root
Apr 12 18:15:57 vmd10967.contabo.host su[8870]: + ??? root:factorio
Apr 12 18:15:57 vmd10967.contabo.host su[8870]: pam_unix(su:session): session opened for user factorio by (uid=0)
Apr 12 18:15:57 vmd10967.contabo.host su[8870]: pam_unix(su:session): session closed for user factorio
Apr 12 18:15:57 vmd10967.contabo.host factorio[8851]: Error! Unable to find any saves in /opt/factorio/saves
Apr 12 18:15:57 vmd10967.contabo.host systemd[1]: factorio.service: control process exited, code=exited status=1
Apr 12 18:15:57 vmd10967.contabo.host systemd[1]: Failed to start (null).
Apr 12 18:15:57 vmd10967.contabo.host systemd[1]: Unit factorio.service entered failed state.

in my factorio folder there is no Factorio.pid file! Is this file supposed to be generated? Or am I supposed to copy this file from somewhere else?
System info: Debian headless server

factorio.service for upstart

Any chance you could enhance the service page and readme to include instructions for upstart users?

Please 👍

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.