Suspend Linux Server When unused?

Anything that prevents you from playing the game properly. Do you have issues playing for the game, downloading it or successfully running it on your computer? Let us know here.
LizardKing
Manual Inserter
Manual Inserter
Posts: 1
Joined: Sat Jun 11, 2016 3:10 pm
Contact:

Suspend Linux Server When unused?

Post by LizardKing »

Hello Factorio Forum! :)
I just set up a headless Linux server on an old computer of mine. (Ubuntu 15.something I think)
Since I don't want to have it running day and night I set up wake on LAN so that a connection would trigger
The computer to turn on.

The problem is however: sending it back to hibernating. I can of course tell Linux to shut down or hibernate after a specific
Amount of time, but this will also happen if people are connected. :(

I'd like my system to go to sleep like 15 minutes after nobody is on the server anymore.
Is there a way to have the server send a signal if it's empty or something?

I know this is more of a Linux / programming question than a factorio question :3
Also: I don't think that this belongs in multiplayer rather than technical help, but if it does: please move it :)

Thank you very much :)
User avatar
prg
Filter Inserter
Filter Inserter
Posts: 947
Joined: Mon Jan 19, 2015 12:39 am
Contact:

Re: Suspend Linux Server When unused?

Post by prg »

Go through the mess of the log file, count connections/disconnections? In 0.13 there will be on_player_joined_game and on_player_left_game events that could be used to output a noticeable message at the right time. For now you could maybe add a snippet of code to the save game's control.lua to output the number of connected players every minute or so, then parse the log file with an external tool and hibernate if you get zero 15 times in a row.

Code: Select all

script.on_event(defines.events.on_tick, function(event)
    if (event.tick % 3600 ~= 0) then return end
    local count = 0
    for _, player in pairs(game.players) do
        if player.connected then count = count + 1 end
    end
    log("Number of players connected: " .. count)
end)
This will only produce output for zero people connected if you don't use the auto pause feature. But if you do use auto pause and the server isn't producing any output, that might already be a hint that nothing's going on currently.
Automatic Belt (and pipe) Planner—Automate yet another aspect of constructing your factory!
Post Reply

Return to “Technical Help”