headless mode on windows 10; system unable to sleep

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.
Post Reply
antares14943
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Aug 22, 2019 3:20 am
Contact:

headless mode on windows 10; system unable to sleep

Post by antares14943 »

I run Factorio in headless mode on a spare machine in my home. I want the machine to sleep at night. This worked in 0.16 by default. I'm running 0.17.56 and this doesn't seem to work this way anymore.

I've tried setting SDL_HINT_VIDEO_ALLOW_SCREENSAVER=1, I've looked at https://wiki.libsdl.org/CategoryHints for more ideas, I've checked wiki for config parameters, and googled a bunch. I haven't been able to find anything that helps.

powercfg reports Factorio is the only thing preventing the system from sleeping:
Capture.PNG
Capture.PNG (91.46 KiB) Viewed 1627 times
Any ideas? Thanks in advance!

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by Rseding91 »

Shut down the server before you put it into sleep mode.

The game specifically tells windows to disallow sleep while it's running because it's a resource intensive game and the system should not be entering sleep mode while it's running.
If you want to get ahold of me I'm almost always on Discord.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2919
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by Optera »

If the server is set to pause while there are no players connected, windows should be allowed to enter sleep.

Otherwise it makes little sense to let it go to sleep while running game updates.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13242
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by Rseding91 »

Optera wrote:
Sat Aug 24, 2019 7:49 pm
If the server is set to pause while there are no players connected, windows should be allowed to enter sleep.

Otherwise it makes little sense to let it go to sleep while running game updates.
It's running a always-on service. It makes no sense to me that it would ever tell the OS: "hey, I know i'm an always-on service but if you feel like it you can shut me off".

You can always manually enter sleep mode; all it does is tell the OS to "please don't do it". The game suggests to the OS it shouldn't - because - it's an always-on service.
If you want to get ahold of me I'm almost always on Discord.

Adamo
Filter Inserter
Filter Inserter
Posts: 479
Joined: Sat May 24, 2014 7:00 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by Adamo »

The server demanding that the system not go to sleep is a feature, not a bug, in this case. It's saying "Hey, you forgot about me!" It makes little sense to run a service that is actively expecting connections while putting the system to sleep. How would it then know when a new connection is incoming? This won't be stable for the game, anyway, without some serious engineering. A sleep process on a server, whether it's running Windows, linux, or whatever, that expects to sleep (why, again, is a server going to sleep?) while running a headless server should have a scripted shutdown process that understands to save and shutdown the factorio server before entering sleep mode, and then to bring it back up when it comes out of sleep.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2919
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by Optera »

Fair points.

So for the OPs scenario where the server should be down for the night he should run Factorio through windows taskmanager.
Start the task in the morning and use taskkill to shut it down in the evening.

Here's the batch script I used to kill currently running instances and start a fresh instance.

Code: Select all

@Echo Off
tasklist /FI "IMAGENAME eq factorio.exe" | findstr "factorio.exe" >nul
if %ERRORLEVEL% == 1 goto StartFactorio
goto StopFactorio

:StopFactorio
REM Echo stopping current instance(s)
REM gracefully stop server
REM timeout /T 60

Echo killing current instance(s)
taskkill /IM factorio.exe /T /F
timeout /T 1

:StartFactorio
Echo starting Factorio
"./bin/x64/factorio.exe" --start-server "./saves/my-save.zip"
Using batch files and taskkill proved to work a lot more reliable than trying to control the executable directly through taskmanager.
I've been using this script to ensure only one instance of a certain program is freshly started since XP and it still works on 10. I'm sure you could do it more elegant with powershell, but I'm not going to reinvent the wheel.

PS: If there is a command to save server state and quit that should be used before force killing the process with taskkill.

User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 2421
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by BlueTemplar »

Note that while making the PC sleep while running a (paused) game of Factorio is not officially supported, I personally never had any issues with it.
(with non-headless Factorio, on Windows and Xubuntu. Meanwhile Ubuntu had issues.)
BobDiggity (mod-scenario-pack)

antares14943
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Aug 22, 2019 3:20 am
Contact:

Re: headless mode on windows 10; system unable to sleep

Post by antares14943 »

Thanks for everyone's help so far. If I'm understanding right, 0.17 added a feature that tells the OS "don't sleep plz". Would it be possible to add a feature flag around this? Ideally I would like my server to sleep after the Factorio process is paused for N minutes. --allow_sleep_when_paused N maybe?

Use case is that my server is another windows 10 machine in my home. Running & cooling it costs money. My users are trained to send a WoL packet to the machine if they want to play. It's a handful of close, technically minded friends so it's manageable.

I could schedule a shutdown script to run. (Ty Optera!) It would be nice if there was a way to check for connected players & delay shutdown if players are connected. Is there a way to do that via an API or a script?

Thanks!

Post Reply

Return to “Technical Help”