[linux] Dedicated server init script

Find multiplayer games.
Tools/scripts to run a dedicated server.
dannyus
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Jun 03, 2015 7:30 pm
Contact:

Re: [linux] Dedicated server init script

Post by dannyus »

Hello, I tried to follow the instructions, and everything works fine, except when i type: "service factorio start" it will tell me this: Failed to start factorio.service: Unit factorio.service failed to load: No such file or directory.

I have no idea what i did wrong, since "service factorio help" works normally and gives me the list of aviable commands. Can anyone please help me?

Thanks :)

EDIT: Ok, nevermind, I got it to work.. just took some fiddling and googling :D
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

dannyus wrote:EDIT: Ok, nevermind, I got it to work.. just took some fiddling and googling :D
If you found any useful information to resolve your problem, please share it with us here :)
Hosting a factorio server? Take a look at this || init script ||.
dannyus
Burner Inserter
Burner Inserter
Posts: 11
Joined: Wed Jun 03, 2015 7:30 pm
Contact:

Re: [linux] Dedicated server init script

Post by dannyus »

Bisa wrote: If you found any useful information to resolve your problem, please share it with us here :)
Ok :D So, in order to be able to launch this script I did this: "cd /opt/factorio-init/" and then: "/etc/init.d/factorio start" and it works. This was my first experience with the linux headless server, so I am not very experienced.. For example I still dont know what the USERNAME and GROUP things are, because if I have anything else than root written in it, It just dont work :D

Also, I highly suggest to everyone to use google virtual machine thingie (https://cloud.google.com/), because you have free 60 days trial. And also I have found this really neat tutorial for setting up the server https://cloud.google.com/solutions/gami ... aft-server. It is for minecraft, but you can safely use it for factorio (change "minecraft" to "factorio" everywhere :D ) At least thats what I did :D And it works and now we have a working server for me and my friends :)
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

dannyus wrote: USERNAME and GROUP things are, because if I have anything else than root written in it, It just dont work :D
That's the systems usergroup and user under which you wish to run factorio, I would set up a specific user named "factorio" on your server and assign all files in /opt/factorio to it (then update the init config setting USERNAME and GROUP to =factorio)

I made a minor edit to the wiki suggesting the use of a separate user. https://wiki.factorio.com/index.php?tit ... ayer#Linux
Hosting a factorio server? Take a look at this || init script ||.
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

I just added support for multiple update packages, non-auth-requirment for headless downloads and other assorted trickery - bringing you a pretty nifty init script for a headless factorio server

git clone https://github.com/Bisa/factorio-init today ;)
Hosting a factorio server? Take a look at this || init script ||.
McBirdy
Manual Inserter
Manual Inserter
Posts: 2
Joined: Mon Mar 14, 2016 3:32 pm
Contact:

Re: [linux] Dedicated server init script

Post by McBirdy »

Amazing tool that I've been using all weekend.

One thing I was looking into today was launching multiple instances of the factorio application on my server at different ports. I see that the factorio executable supports custom config files with the -c [--config] option. And I got this to work by running it manually alongside the one started by the factorio-init script.

I'm sure this is something that can be implemented as well. I might look into it over the easter holiday. It would need a slightly different way of handling the save games, as they are named factorio-init-save today.
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

McBirdy wrote:I'm sure this is something that can be implemented as well. I might look into it over the easter holiday. It would need a slightly different way of handling the save games, as they are named factorio-init-save today.
I've been tinkering with this myself a bit, currently there are a number of options you can set to distinguish between instances, for example

SERVICE_NAME
PIDFILE
SAVE_NAME

feel free to mess around and send me a pull request if you find anything that needs changing :)
Hosting a factorio server? Take a look at this || init script ||.
runningman
Burner Inserter
Burner Inserter
Posts: 8
Joined: Tue Mar 15, 2016 11:19 pm
Contact:

Re: [linux] Dedicated server init script

Post by runningman »

Would be really nice if multiple instances could be managed be the init script. Looking forward to it :)
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

runningman wrote:Would be really nice if multiple instances could be managed be the init script. Looking forward to it :)
right now - the only ways this script will support multiple instances is if you mod the factorio.service.example to load a different config per "instance" or copy the script to a separate directory per instance (if you're using the screen approach)

I don't feel adding multi instance support to a init script is a good design approach since the various init systems out there already support this - but I def want to ensure the script can be separated with different configs withot it's internals interfering with other instances (unless it does that already)
Hosting a factorio server? Take a look at this || init script ||.
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

just pushed a correction for the now removed "SCREEN_NAME" which will hopefully make it easier to run multiple copies of this script by allowing you to set a separate "SERVICE_NAME" for each instance
Hosting a factorio server? Take a look at this || init script ||.
Bonesaw
Manual Inserter
Manual Inserter
Posts: 3
Joined: Tue Mar 08, 2016 3:38 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bonesaw »

Hi Bisa,

Looking at the README.md at the end it talks about getting systemd set up with factorio. But... as I learned systemctl is the systemd tool and that tool is not present nor used on Ubuntu 14.04 as it uses Upstart. Do you know, or anyone else for that matter, have a .conf file that can be used with Upstart?
sirmg
Burner Inserter
Burner Inserter
Posts: 7
Joined: Thu Mar 17, 2016 6:23 pm
Contact:

Re: [linux] Dedicated server init script

Post by sirmg »

I just installed the new version now i get this error:

Code: Select all

root@ubuntu-Vserver:/usr/local/factorio# service factorio start
/etc/init.d/factorio: line 112: [: too many arguments
/etc/init.d/factorio: line 114: [: too many arguments
WhiteORU
Burner Inserter
Burner Inserter
Posts: 9
Joined: Wed Mar 23, 2016 2:11 pm
Contact:

Re: [linux] Dedicated server init script

Post by WhiteORU »

help

Code: Select all

***:***/***# service factorio start
Job for factorio.service failed. See 'systemctl status factorio.service' and 'journalctl -xn' for details.
***:/***/***# systemctl status factorio.service
● factorio.service - (null)
   Loaded: loaded (/etc/init.d/factorio)
   Active: failed (Result: exit-code) since Ср 2016-03-23 10:16:34 EDT; 6s ago
  Process: 8067 ExecStart=/etc/init.d/factorio start (code=exited, status=1/FAILURE)

мар 23 10:16:24 *** su[8086]: pam_unix(su:session): session opened for user factorio by (uid=0)
мар 23 10:16:24 *** su[8088]: Successful su for factorio by root
мар 23 10:16:24 *** su[8088]: + ??? root:factorio
мар 23 10:16:24 *** su[8088]: pam_unix(su:session): session opened for user factorio by (uid=0)
мар 23 10:16:24 *** su[8088]: pam_unix(su:session): session closed for user factorio
мар 23 10:16:26 *** factorio[8067]: Still not running, waiting a while longer...
мар 23 10:16:34 *** factorio[8067]: Failed to start, aborting.
мар 23 10:16:34 *** systemd[1]: factorio.service: control process exited, code=exited status=1
мар 23 10:16:34 *** systemd[1]: Failed to start (null).
мар 23 10:16:34 *** systemd[1]: Unit factorio.service entered failed state.
***:/***/***#  
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

Startup errors ought to be fixed now - silly me, I should not add features this light headed....
Hosting a factorio server? Take a look at this || init script ||.
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

Bonesaw wrote:Hi Bisa,
Looking at the README.md at the end it talks about getting systemd set up with factorio. But... as I learned systemctl is the systemd tool and that tool is not present nor used on Ubuntu 14.04 as it uses Upstart. Do you know, or anyone else for that matter, have a .conf file that can be used with Upstart?
I never really looked into upstart, if you write an example for upstart - feel free to share it with the rest of us :)

Edit
actually, have a look at this answer on askubuntu http://askubuntu.com/questions/22099/wa ... and-advice
I can imagine all you need to do is something similar to this:

Code: Select all

description     "Factorio server"

expect fork
start on runlevel [3]
stop on runlevel [!2345]
respawn
script
    su -c "/path/to/factorio-init/factorio refresh-save" factorio
    su -c "/path/to/factorio-init/factorio start" factorio
end script
now I did not test this, but it should hopefully point you in the right direction ;)
Hosting a factorio server? Take a look at this || init script ||.
WhiteORU
Burner Inserter
Burner Inserter
Posts: 9
Joined: Wed Mar 23, 2016 2:11 pm
Contact:

Re: [linux] Dedicated server init script

Post by WhiteORU »

Last 0.12.29 factorio and last factorio-init version

Failed to start factorio.service: Unit factorio.service failed to load: No such file or directory.
I do as https://wiki.factorio.com/index.php?tit ... ayer#Linux and https://github.com/Bisa/factorio-init/b ... /README.md after setup i see viewtopic.php?f=133&t=13874&p=139500#p139276
my system

Code: Select all

****:/opt# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 8.3 (jessie)
Release:        8.3
Codename:       jessie
check libs

Code: Select all

****:/opt# ldd /opt/factorio/bin/x64/factorio
        linux-vdso.so.1 (0x00007ffe5a96b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f57d5714000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f57d550c000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f57d520a000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f57d4ff4000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f57d4c49000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f57d593a000)
opt folder

Code: Select all

drwxrwxr-x 8 factorio factorio 4096 Mar 23 11:40 factorio
drwxrwxrwx 3 factorio factorio 4096 Mar 23 19:22 factorio-init
factorio folder

Code: Select all

-rw-r--r-- 1 factorio factorio    0 Mar 23 11:24 Factorio.pid
drwxr-xr-x 3 factorio factorio 4.0K Mar 23 09:50 bin
drwxr-xr-x 2 factorio factorio 4.0K Mar 23 11:39 config
-rw-r--r-- 1 factorio factorio  998 Jul 13  2015 config-path.cfg
drwxr-xr-x 4 factorio factorio 4.0K Mar 18 12:57 data
-rw-r--r-- 1 factorio factorio 8.1K Mar 23 11:41 factorio-current.log
-rw-r--r-- 1 factorio factorio 3.0K Mar 23 11:39 factorio-previous.log
drwxr-xr-x 2 factorio factorio 4.0K Mar 23 11:39 mods
-rw-r--r-- 1 factorio factorio  402 Mar 23 11:39 player-data.json
drwxr-xr-x 2 factorio factorio 4.0K Mar 23 11:39 saves
drwxr-xr-x 3 factorio factorio 4.0K Mar 23 11:40 temp
factorio-init folder

Code: Select all

-rw-r--r-- 1 root     root     1.1K Mar 23 19:21 LICENSE
-rw-r--r-- 1 factorio factorio 1.6K Mar 23 19:21 README.md
-rw-r--r-- 1 root     root     2.5K Mar 23 19:22 config
-rw-r--r-- 1 root     root     2.5K Mar 23 19:21 config.example
-rwxr-xr-x 1 root     root      12K Mar 23 19:21 factorio
-rw-r--r-- 1 root     root      621 Mar 23 19:21 factorio.service.example
but factorio user start factorio succes

Code: Select all

****:/opt#su factorio
/opt/factorio/bin/x64/factorio --start-server save
   0.000 2016-03-23 20:05:33; Factorio 0.12.28 (Build 17913, linux64, headless)
   0.017 Operating system: Linux (Debian 8.3)
   0.017 Program arguments: "/opt/factorio/bin/x64/factorio" "--start-server" "save"
   0.017 Read data path: /opt/factorio/data
   0.017 Write data path: /opt/factorio
   0.017 Binaries path: /opt/factorio/bin
   0.023 Running in headless mode
   0.026 Loading mod core 0.0.0 (data.lua)
   0.027 Loading mod base 0.12.28 (data.lua)
   0.068 Loading mod marathon 1.0.1 (data.lua)
   0.110 Loading mod marathon 1.0.1 (data-updates.lua)
   0.364 Factorio initialised
   0.365 Info Router.cpp:507: Router peerID(65535) shutting down.
   0.365 Info Router.cpp:534: Router state -> Disconnected
   0.365 Info MultiplayerManager.cpp:912: networkTick(0) mapTick(-1) changing state from(Ready) to(PreparedToHostGame)
   0.365 Info MultiplayerManager.cpp:912: networkTick(0) mapTick(-1) changing state from(PreparedToHostGame) to(CreatingGame)
   0.365 Loading map /opt/factorio/saves/save.zip
   0.378 Info Scenario.cpp:124: Map version 0.12.28-1
   0.827 Info MultiplayerManager.cpp:281: 0x7f54ab56e350, (nil)
   0.827 Info PosixUDPSocket.cpp:34: Opening socket at port 34197
   0.827 Info Router.cpp:534: Router state -> Connected
   0.827 Info Synchronizer.cpp:54: NetworkTick(0) initialized Synchronizer local peer(0) latency(6).
   0.827 Hosting game at port 34197, peerID 0, session magic 3677
   0.827 Info MultiplayerManager.cpp:303: 0x7f54ab56e350, 0x7f54ab56e350
   0.827 Info MultiplayerManager.cpp:912: networkTick(0) mapTick(10356399) changing state from(CreatingGame) to(InGame)
   0.827 Info NetworkInputHandler.cpp:45: mapTick(10356399) networkTick(0) initialized NetworkInputHandler local peer(0).
   0.944 Info MultiplayerManager.cpp:1411: Received peer info for peer(0) username(<server>).
   0.944 Info MultiplayerManager.cpp:1059: networkTick(6) mapTick(10356399) received stateChanged peerID(0) oldState(Ready) newState(CreatingGame)
   0.944 Info MultiplayerManager.cpp:1059: networkTick(6) mapTick(10356399) received stateChanged peerID(0) oldState(CreatingGame) newState(InGame)
and manually start

Code: Select all

****:/opt/factorio-init# ./factorio start
Factorio is running.
factorio.servise.example should be called factorio.service in /opt/factorio-init ?
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

WhiteORU wrote: Failed to start factorio.service: Unit factorio.service failed to load: No such file or directory.
This seems to be your issue right there, did you add a service file? (you can copy/symlink the factorio.service.example and update its content based on your own environment)
Hosting a factorio server? Take a look at this || init script ||.
gloix
Manual Inserter
Manual Inserter
Posts: 4
Joined: Fri Mar 25, 2016 8:18 pm
Contact:

Re: [linux] Dedicated server init script

Post by gloix »

Why does the init script generate another save file instead of using the original?
From what I understand:
- If I start the server with save1.zip, a copy of that will be generated.
- Play a few days.
- Start the server with another save -> all recent progress of save1 is lost since it was in the dummy file factorio-init-save.zip
Bisa
Filter Inserter
Filter Inserter
Posts: 450
Joined: Fri Jul 17, 2015 3:22 pm
Contact:

Re: [linux] Dedicated server init script

Post by Bisa »

gloix wrote:Why does the init script generate another save file instead of using the original?
The save name, or rather the entire invocation with all its arguments is used to find which process id the server runs as. I opted to keep a static name used for this reason - as such, if you want to play different save games you need to manually copy them aside and use "load-save" to play the one you want to use right now.

(while it never crossed my mind before I guess a similar command "copy-save" could find usage for a limited number of users - feel free to implement and pull request if you want to :) )
Hosting a factorio server? Take a look at this || init script ||.
PCVXD
Manual Inserter
Manual Inserter
Posts: 1
Joined: Tue Mar 29, 2016 9:20 am
Contact:

Re: [linux] Dedicated server init script

Post by PCVXD »

It won't start on my server. When I execute service factorio start it gives an error in the debug log: could not find a pid for binary: "/opt/factorio/bin/x64/factorio". service factorio help does work. I also have all the dependencies. The Systemd part seems to be running succesfully. How can I solve this? I am a Linux newbie.
Post Reply

Return to “Multiplayer / Dedicated Server”