Page 1 of 1

Linux Headless Not starting

Posted: Wed Mar 09, 2016 8:37 pm
by astronouth7303
So I got factorio headless all set up, all the things in their places, and then this.

Code: Select all

   0.004 2016-03-09 13:37:58; Factorio 0.12.26 (Build 17762, linux64)
   0.385 Operating system: Linux (Ubuntu 15.10)
   0.387 Program arguments: "/home/factorio/factorio/bin/x64/factorio" "--start-server" "factorio-init-save" 
   0.388 Read data path: /home/factorio/factorio/data
   0.388 Write data path: /home/factorio/factorio
   0.388 Binaries path: /home/factorio/factorio/bin
   0.468 Running in headless mode
   0.477 Loading mod core 0.0.0 (data.lua)
   0.485 Loading mod base 0.12.26 (data.lua)
   1.408 Factorio initialised
   1.416 Info Router.cpp:556: Router peerID(65535) shutting down.
   1.417 Info Router.cpp:582: Router state -> Disconnected
   1.417 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(-1) changing state from(Ready) to(PreparedToHostGame)
   1.421 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(-1) changing state from(PreparedToHostGame) to(CreatingGame)
   1.422 Loading map /home/factorio/factorio/saves/factorio-init-save.zip
   1.466 Info Scenario.cpp:124: Map version 0.12.26-0
   3.313 Info MultiplayerManager.cpp:282: 0x7f6a2309acd0, (nil)
   3.318 Info PosixUDPSocket.cpp:34: Opening socket at port 34197
   3.320 Info Router.cpp:582: Router state -> Connected
   3.320 Info Synchronizer.cpp:54: NetworkTick(0) initialized Synchronizer local peer(0) latency(6).
   3.321 Hosting game at port 34197, peerID 0, session magic 1011
   3.321 Info MultiplayerManager.cpp:304: 0x7f6a2309acd0, 0x7f6a2309acd0
   3.322 Info MultiplayerManager.cpp:906: networkTick(0) mapTick(2524439) changing state from(CreatingGame) to(InGame)
   3.322 Info NetworkInputHandler.cpp:40: mapTick(2524439) networkTick(0) initialized NetworkInputHandler local peer(0).
   3.441 Info MultiplayerManager.cpp:1385: Received peer info for peer(0) username(<server>).
   3.441 Info MultiplayerManager.cpp:1043: networkTick(6) mapTick(2524439) received stateChanged peerID(0) oldState(Ready) newState(CreatingGame)
   3.442 Info MultiplayerManager.cpp:1043: networkTick(6) mapTick(2524439) received stateChanged peerID(0) oldState(CreatingGame) newState(InGame)
   6.801 Received SIGINT, shutting down
   7.763 Warning NetworkInputHandler.cpp:723: mapTick(2524439) networkTick(208) disconnecting from player but already disconnected.
   7.933 Info MultiplayerManager.cpp:134: NetworkTick(208) disconnecting multiplayer connection.
   7.933 Info NetworkInputHandler.cpp:59: expectedMapTick(2524439) sending PlayerLeaveGame
   7.943 Info MultiplayerManager.cpp:161: NetworkTick(208) quitting multiplayer connection.
   7.943 Info MultiplayerManager.cpp:906: networkTick(208) mapTick(-1) changing state from(InGame) to(Disconnected)
   7.986 Info Router.cpp:556: Router peerID(0) shutting down.
   7.998 Info PosixUDPSocket.cpp:127: Socket closed
   7.998 Info Router.cpp:582: Router state -> Disconnected
   7.999 Goodbye
Notice 6.801: "Received SIGINT, shutting down"
No, I'm not hitting Ctrl-C.

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 9:04 pm
by prg
Are you running Factorio manually or using some script that might be doing things behind your back?

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 9:13 pm
by astronouth7303
prg wrote:Are you running Factorio manually or using some script that might be doing things behind your back?
I've tried both. This particular run came from running it manually.

(The script I'm using is factorio-init.)

Weirdly, it does the same thing if I run it under gdb, but is fine if I run it under strace.

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 9:19 pm
by prg
Does the script maybe not exit cleanly and still run something like kill -INT $(pidof factorio) from time to time?

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 9:26 pm
by astronouth7303
prg wrote:Does the script maybe not exit cleanly and still run something like kill -INT $(pidof factorio) from time to time?
Don't think so, because strace still has a copy running, similar to gdb.

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 10:02 pm
by Oxyd
Well, factorio-init contains the following:

Code: Select all

find_pid(){
  pid=$(ps ax | grep -v grep | grep "${BINARY} --start-server ${SAVE_NAME}" | grep -v "${SCREEN_NAME}" | awk '{ print $1}')
# ...
}

# ...

stop_service() {

  #
  # Stops the server
  #
  pid=$(find_pid)
  as_user "kill -s 2 ${pid}"

# ...
}
stop_service is called from multiple places in that script. Since it uses ps to get Factorio's PID and then happily signals whatever Factorio it can find, it could kill an instance you started manually, if you then run the script whilst Factorio is running.

In any case, something or someone is sending SIGINT to your Factorio, so find out who or what.

Edit: Also, did you install the systemd service that's a part of that repository? The systemd script contains

Code: Select all

TimeoutStartSec=5
and, according to man systemd.service:

Code: Select all

TimeoutStartSec=
        Configures the time to wait for start-up. If a daemon service does not signal start-up completion within the configured time, the service will be considered failed and will be shut down again.
Since Factorio isn't systemd-aware, it won't signal systemd that it completed startup, so systemd will consider it failed after 5 seconds and will try to restart it.

So, try systemctl stop factorio, and try running it manually again. If it works this time, the systemd service is the culprit.

Re: Linux Headless Not starting

Posted: Wed Mar 09, 2016 10:47 pm
by astronouth7303
Yeah, Systemd was causing the problems. Systemd was killing factorio, but only sometimes. (In true systemd fashion.)

Of course, in trying to get the other features of the script working, I ended up not using systemd services and installing it as an rc.