[GH-ISSUE #4072] Ollama should prevent sleep when working. #2529

Open
opened 2026-04-12 12:51:08 -05:00 by GiteaMirror · 36 comments
Owner

Originally created by @owenzhao on GitHub (May 1, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4072

Originally assigned to: @dhiltgen on GitHub.

I am using Ollama 0.1.32 on Windows 11. Ollama is set to provide LLMs on LAN. However, when I use it, sometimes the Windows goes sleep mode when I am waiting Ollama answering questions using API.

So I guess Ollama does not prevent Windows 11 into sleep even through Ollama is working.

Ollama is install natively, not docker.

Originally created by @owenzhao on GitHub (May 1, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4072 Originally assigned to: @dhiltgen on GitHub. I am using Ollama 0.1.32 on Windows 11. Ollama is set to provide LLMs on LAN. However, when I use it, sometimes the Windows goes sleep mode when I am waiting Ollama answering questions using API. So I guess Ollama does not prevent Windows 11 into sleep even through Ollama is working. Ollama is install natively, not docker.
GiteaMirror added the feature requestgood first issuewindows labels 2026-04-12 12:51:08 -05:00
Author
Owner

@molbal commented on GitHub (May 1, 2024):

I do not think this is an Ollama question - you are using the consumer version of Windows as a server. That being said, I recommend using this Powertoys utility as a workaround: https://learn.microsoft.com/en-us/windows/powertoys/awake

<!-- gh-comment-id:2088169655 --> @molbal commented on GitHub (May 1, 2024): I do not think this is an Ollama question - you are using the consumer version of Windows as a server. That being said, I recommend using this Powertoys utility as a workaround: https://learn.microsoft.com/en-us/windows/powertoys/awake
Author
Owner

@owenzhao commented on GitHub (May 1, 2024):

I do not think this is an Ollama question - you are using the consumer version of Windows as a server. That being said, I recommend using this Powertoys utility as a workaround: https://learn.microsoft.com/en-us/windows/powertoys/awake

Thanks. But I don't think this is a good approach.

Even with a consumer version of Windows, an app prevent the system into sleep is very common. I believe you must have used this kind of apps. For example, Video Player like MPV can prevent the system into sleep during playing movies. Music players can prevent the system into sleep when a song is played.

Powertoys can prevent the system sleep when a specified process is running by its pid. But that is not what I expected. As my idea is to prevent the system sleep only when Ollama is working. If the Ollama server is started but waiting in background, it should not prevent the system into sleep. It is just like the video players, only prevent the system into sleep when a video is playing.

Also, even with a consumer version of Windows, the prevent sleep API is provided by the system. So there should no different whether the system is a consumer version or a server version.

If I design this feature in Ollama, I will extend the time length of preventing the system into sleep every time Ollama answers a question. Five minutes will be enough.

<!-- gh-comment-id:2088269915 --> @owenzhao commented on GitHub (May 1, 2024): > I do not think this is an Ollama question - you are using the consumer version of Windows as a server. That being said, I recommend using this Powertoys utility as a workaround: https://learn.microsoft.com/en-us/windows/powertoys/awake Thanks. But I don't think this is a good approach. Even with a consumer version of Windows, an app prevent the system into sleep is very common. I believe you must have used this kind of apps. For example, Video Player like MPV can prevent the system into sleep during playing movies. Music players can prevent the system into sleep when a song is played. Powertoys can prevent the system sleep when a specified process is running by its pid. But that is not what I expected. As my idea is to prevent the system sleep only when Ollama is working. If the Ollama server is started but waiting in background, it should not prevent the system into sleep. It is just like the video players, only prevent the system into sleep when a video is playing. Also, even with a consumer version of Windows, the prevent sleep API is provided by the system. So there should no different whether the system is a consumer version or a server version. If I design this feature in Ollama, I will extend the time length of preventing the system into sleep every time Ollama answers a question. Five minutes will be enough.
Author
Owner

@dhiltgen commented on GitHub (May 1, 2024):

This looks like a good first issue.

https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

ddc2195639/process.go (L144)

Wired into the scheduler to toggle state when there is (or isn't) an active runner.

<!-- gh-comment-id:2089079180 --> @dhiltgen commented on GitHub (May 1, 2024): This looks like a good first issue. https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate https://github.com/kumako/go-win64api/blob/ddc2195639e59051ca979119193c5013bf521ef3/process.go#L144 Wired into the scheduler to toggle state when there is (or isn't) an active runner.
Author
Owner

@centopw commented on GitHub (May 2, 2024):

I think it would be handy to add an option in the settings or menu to toggle "Keep PC Awake" in Ollama. Not everyone needs their PC to stay awake while using it, so having this option would be great for those who do and for those who don't. It's all about giving users the choice they want. What do you think?

<!-- gh-comment-id:2089438978 --> @centopw commented on GitHub (May 2, 2024): I think it would be handy to add an option in the settings or menu to toggle "Keep PC Awake" in Ollama. Not everyone needs their PC to stay awake while using it, so having this option would be great for those who do and for those who don't. It's all about giving users the choice they want. What do you think?
Author
Owner

@eirnym commented on GitHub (May 9, 2024):

@owenzhao My guess based on a description of your setup, is windows machine is set up as a ollama server. The server once in a while goes to sleep as you described. You requested that when Ollama is working, Windows machine should not go to sleep and when ollama is not working Windows machine should be allowed to go to sleep.

I propose a complex solution which could satisfy your needs.

  1. Setup Ollama as a windows service with manual startup. There's numerous ways to do that, from a single line in a terminal to packaging to an installer. Choose your preferred method.
  2. Run Ollama with desired settings to work with it.
  3. There's also numerous options how to make windows awake as long as specific PID process is awake. If powertoys or similar tools has been used, after service successfully run, get service PID and use it. Other option is to select respective previously created Power Settings on start and end of serving.
  4. After job required Ollama has done, created ollama service may be shut down and sleep prevention as well.
  5. A neat option is also to use Wake-On-Lan or similar feature to wake up server when required and sending to sleep when it's not.

Please note, that it's not common and it's not recommended to prevent sleeping when working from a service. it's generally considered a bad and dangerous practice and there's many other workarounds. Usually when a computer is in server role, it runs all the time without going to sleep (see my suggestion on power/battery settings).

<!-- gh-comment-id:2102646416 --> @eirnym commented on GitHub (May 9, 2024): @owenzhao My guess based on a description of your setup, is windows machine is set up as a ollama server. The server once in a while goes to sleep as you described. You requested that when Ollama is working, Windows machine should not go to sleep and when ollama is not working Windows machine should be allowed to go to sleep. I propose a complex solution which could satisfy your needs. 1. Setup Ollama as a windows service with manual startup. There's numerous ways to do that, from a single line in a terminal to packaging to an installer. Choose your preferred method. 2. Run Ollama with desired settings to work with it. 3. There's also numerous options how to make windows awake as long as specific PID process is awake. If powertoys or similar tools has been used, after service successfully run, get service PID and use it. Other option is to select respective previously created Power Settings on start and end of serving. 4. After job required Ollama has done, created ollama service may be shut down and sleep prevention as well. 5. A neat option is also to use Wake-On-Lan or similar feature to wake up server when required and sending to sleep when it's not. Please note, that it's not common and it's not recommended to prevent sleeping when working from a service. it's generally considered a bad and dangerous practice and there's many other workarounds. Usually when a computer is in server role, it runs all the time without going to sleep (see my suggestion on power/battery settings).
Author
Owner

@owenzhao commented on GitHub (May 9, 2024):

I found that many of the replies were not got what I meant. So I want to reclaim what I mean.

First, many of you mixed Ollama server started in background and was working. So the suggestions were useless.

When Windows system starts, Ollama server starts alone with it. There is no settings need to do on that. That is the default behavior of Ollama.exe.

When Ollama server starts and no one is using it, I call it starts in background.

If I start my own app and use Ollama API to connect with Ollama server, I call it is working.

My intent is not kept Windows awake when Ollama server starts in background, which is many of you suggest to use PID with power toy. Again, that was not my intent. My intent is to stop Windows to sleep when I call the Ollama's API and waiting the results.

Currently, sometimes when I called Ollama API and was waiting the result or just got the result and before I called the next Ollama API, the Windows slept. That was very odd and I think should be changed.

<!-- gh-comment-id:2103189679 --> @owenzhao commented on GitHub (May 9, 2024): I found that many of the replies were not got what I meant. So I want to reclaim what I mean. First, many of you mixed Ollama server started in background and was working. So the suggestions were useless. When Windows system starts, Ollama server starts alone with it. There is no settings need to do on that. That is the default behavior of Ollama.exe. When Ollama server starts and no one is using it, I call it starts in background. If I start my own app and use Ollama API to connect with Ollama server, I call it is working. My intent is not kept Windows awake when Ollama server starts in background, which is many of you suggest to use PID with power toy. Again, that was not my intent. My intent is to stop Windows to sleep when I call the Ollama's API and waiting the results. Currently, sometimes when I called Ollama API and was waiting the result or just got the result and before I called the next Ollama API, the Windows slept. That was very odd and I think should be changed.
Author
Owner

@eirnym commented on GitHub (May 10, 2024):

@owenzhao

Ollama starts when windows starts.

It could be handy when you work on the same computer. To start and stop a service efficiently there's windows services and they are universal.

Also automatic services start automatically without logging in.

my intent to stop Ollama to prevent Windows to sleep when I call it.

I don't know how you use it, proposed solution should be good for others as well. I use Ollama sporadically or within IDE, e.g. I expect it running when I work, not per a single request.

And based on console logs and local tests, when I run Ollama in interactive mode it doesn't call Ollama all the time and I can restart a server in between calls. And I prefer to keep it this way.

Thus,proposed solution is a half-ok as server would go to sleep just after a single request goes off and it would be more frustrating as AFAIK programmatic method doesn't reset sleep timer.

Additionally, starting and stopping windows server is much easier than you think as it's an unattended action (ssh can be used as a universal solution).

More so, the best and the most manageable solution is to use required Power Settings, not changing service to prevent OS sleeping, which is the worst practice.

I vote strongly against proposed and against changing how interactive mode works as well.

<!-- gh-comment-id:2104170661 --> @eirnym commented on GitHub (May 10, 2024): @owenzhao > Ollama starts when windows starts. It could be handy when you work on the same computer. To start and stop a service efficiently there's windows services and they are universal. Also automatic services start automatically without logging in. > my intent to stop Ollama to prevent Windows to sleep when I call it. I don't know how you use it, proposed solution should be good for others as well. I use Ollama sporadically or within IDE, e.g. I expect it running when I work, not per a _single_ request. And based on console logs and local tests, when I run Ollama in interactive mode it doesn't call Ollama all the time and I can restart a server in between calls. And I prefer to keep it this way. Thus,proposed solution is a half-ok as server would go to sleep just after a single request goes off and it would be more frustrating as AFAIK programmatic method doesn't reset sleep timer. Additionally, starting and stopping windows server is much easier than you think as it's an unattended action (ssh can be used as a universal solution). More so, the best and the most manageable solution is to use required Power Settings, not changing service to prevent OS sleeping, which is the worst practice. I vote strongly against proposed and against changing how interactive mode works as well.
Author
Owner

@owenzhao commented on GitHub (May 10, 2024):

More so, the best and the most manageable solution is to use required Power Settings, not changing service to prevent OS sleeping, which is the worst practice.

Can you explain why you think it is the worst practice as many other apps can do that and the system is allowed to do that so they provided API. As I pointed out, many movie players can do that. So why that is the worst practice? I don't think there any drawbacks. As the system only awake during the working time, the system can still go to sleep if Ollama is not needed.

<!-- gh-comment-id:2105284002 --> @owenzhao commented on GitHub (May 10, 2024): > More so, the best and the most manageable solution is to use required Power Settings, not changing service to prevent OS sleeping, which is the worst practice. Can you explain why you think it is the worst practice as many other apps can do that and the system is allowed to do that so they provided API. As I pointed out, many movie players can do that. So why that is the worst practice? I don't think there any drawbacks. As the system only awake during the working time, the system can still go to sleep if Ollama is not needed.
Author
Owner

@eirnym commented on GitHub (May 10, 2024):

Can you explain why you think it is the worst practice as many other apps can do that and the system is allowed to do that so they provided API

I don't speak for consumer apps, but for services specifically. The reason is quite simple: the administrator defines how computer should work, not a service. And you is an administrator of your computer. Also if a background app preventing computer to go to sleep and user doesn't aware of it (explicit action/setting), then it becomes a hassle to manage actual power settings and battery life, especially if we speak about laptops. For example, I as a developer usually have multiple services on my laptop and if any of them would prevent sleep without my explicit setting, I'd just remove a service, and if I'd like to run a homelab server on a laptop or desktop, I'd set my power settings in such way, that laptop won't go to sleep till I say so. One of a good examples of such behaviour is community project wsusoffline (and their derivatives).

Video players are kind'a an exception here (not really), as a user stare at screen for a long period of time and doesn't want to be disturbed from an entertainment. Not really as it is a mass user desire.

Simplifying things, Ollama is an ordinary HTTP server (it's written in documentation as well), which provides a main function on the backend to ask model to produce some response on some request, nothing more, nothing else. Response is quite small and limited in time.

<!-- gh-comment-id:2105338494 --> @eirnym commented on GitHub (May 10, 2024): > Can you explain why you think it is the worst practice as many other apps can do that and the system is allowed to do that so they provided API I don't speak for consumer apps, but for services specifically. The reason is quite simple: the administrator defines how computer should work, not a service. And you is an administrator of your computer. Also if a background app preventing computer to go to sleep and user doesn't aware of it (explicit action/setting), then it becomes a hassle to manage actual power settings and battery life, especially if we speak about laptops. For example, I as a developer usually have multiple services on my laptop and if any of them would prevent sleep without my explicit setting, I'd just remove a service, and if I'd like to run a homelab server on a laptop or desktop, I'd set my power settings in such way, that laptop won't go to sleep till I say so. One of a good examples of such behaviour is community project wsusoffline (and their derivatives). Video players are kind'a an exception here (not really), as a user stare at screen for a long period of time and doesn't want to be disturbed from an entertainment. Not really as it is a mass user desire. Simplifying things, Ollama is an ordinary HTTP server (it's written in documentation as well), which provides a main function on the backend to ask model to produce some response on some request, nothing more, nothing else. Response is quite small and limited in time.
Author
Owner

@eirnym commented on GitHub (May 10, 2024):

As the system only awake during the working time, the system can still go to sleep if Ollama is not needed.

the definition of "Ollama is not needed" is quite vague. It serves a request/response, but don't keep connection alive (which I prefer to keep this way), so the only time Ollama actually serves something is when there's an explicit user interaction. Don't take my word and check it yourself. I tested provided commands in my terminal, you can test in any other way you'd like.

  1. Run Ollama serving (command ollama serve)
  2. In other terminal (or computer) run ollama run <model> with any model you already have.
  3. Run a single request to your model
  4. Upon request completion, stop the server
  5. Check in other terminal, that client tells that server is not running by running next request
  6. Spin up server again
  7. And run yet another request, it would reply as server was never offline.

With this out of the way, I'd define "Ollama is needed" as "I have a session with Ollama". The script to run Ollama serving contents and set specific predefined power settings and then stopping Ollama and revert Power Settings is more universal and easier to implement. AFAIK, PowerToys require an active GUI session

  • User doesn't need active GUI session to run and stop a server.
  • It's easy to run remotely via Open SSH as it's built in in WIndows 10+ by Microsoft itself.
  • It's flexible, so you know how to change it's easily by yourself and what exact settings you prefer to have.
  • As it's a potentially scripted solution and you know exact schedule when it's needed, Windows Scheduler could be used.
  • It doesn't break in a hidden way any expectations a user might have.
<!-- gh-comment-id:2105349952 --> @eirnym commented on GitHub (May 10, 2024): > As the system only awake during the working time, the system can still go to sleep if Ollama is not needed. the definition of "Ollama is not needed" is quite vague. It serves a request/response, but don't keep connection alive (which I prefer to keep this way), so the only time Ollama actually serves something is when there's an explicit user interaction. Don't take my word and check it yourself. I tested provided commands in my terminal, you can test in any other way you'd like. 1. Run Ollama serving (command `ollama serve`) 2. In other terminal (or computer) run `ollama run <model>` with any model you already have. 3. Run a single request to your model 4. Upon request completion, stop the server 5. Check in other terminal, that client tells that server is not running by running next request 6. Spin up server again 7. And run yet another request, it would reply as server was never offline. With this out of the way, I'd define "Ollama is needed" as "I have a session with Ollama". The script to run Ollama serving contents and set specific predefined power settings and then stopping Ollama and revert Power Settings is more universal and easier to implement. AFAIK, PowerToys require an active GUI session * User doesn't need active GUI session to run and stop a server. * It's easy to run remotely via Open SSH as it's built in in WIndows 10+ by Microsoft itself. * It's flexible, so you know how to change it's easily by yourself and what exact settings you prefer to have. * As it's a potentially scripted solution and you know exact schedule when it's needed, Windows Scheduler could be used. * It doesn't break in a hidden way any expectations a user might have.
Author
Owner

@owenzhao commented on GitHub (May 11, 2024):

As the system only awake during the working time, the system can still go to sleep if Ollama is not needed.

the definition of "Ollama is not needed" is quite vague. It serves a request/response, but don't keep connection alive (which I prefer to keep this way), so the only time Ollama actually serves something is when there's an explicit user interaction. Don't take my word and check it yourself. I tested provided commands in my terminal, you can test in any other way you'd like.

  1. Run Ollama serving (command ollama serve)
  2. In other terminal (or computer) run ollama run <model> with any model you already have.
  3. Run a single request to your model
  4. Upon request completion, stop the server
  5. Check in other terminal, that client tells that server is not running by running next request
  6. Spin up server again
  7. And run yet another request, it would reply as server was never offline.

With this out of the way, I'd define "Ollama is needed" as "I have a session with Ollama". The script to run Ollama serving contents and set specific predefined power settings and then stopping Ollama and revert Power Settings is more universal and easier to implement. AFAIK, PowerToys require an active GUI session

  • User doesn't need active GUI session to run and stop a server.
  • It's easy to run remotely via Open SSH as it's built in in WIndows 10+ by Microsoft itself.
  • It's flexible, so you know how to change it's easily by yourself and what exact settings you prefer to have.
  • As it's a potentially scripted solution and you know exact schedule when it's needed, Windows Scheduler could be used.
  • It doesn't break in a hidden way any expectations a user might have.

I think we are not talking the same thing. You suggest me to use SSH, so you supposed I am using a remote terminal. I am not. I am using an app that use Ollama's API. So there is no SSH, just http.

<!-- gh-comment-id:2105664526 --> @owenzhao commented on GitHub (May 11, 2024): > > As the system only awake during the working time, the system can still go to sleep if Ollama is not needed. > > the definition of "Ollama is not needed" is quite vague. It serves a request/response, but don't keep connection alive (which I prefer to keep this way), so the only time Ollama actually serves something is when there's an explicit user interaction. Don't take my word and check it yourself. I tested provided commands in my terminal, you can test in any other way you'd like. > > 1. Run Ollama serving (command `ollama serve`) > 2. In other terminal (or computer) run `ollama run <model>` with any model you already have. > 3. Run a single request to your model > 4. Upon request completion, stop the server > 5. Check in other terminal, that client tells that server is not running by running next request > 6. Spin up server again > 7. And run yet another request, it would reply as server was never offline. > > With this out of the way, I'd define "Ollama is needed" as "I have a session with Ollama". The script to run Ollama serving contents and set specific predefined power settings and then stopping Ollama and revert Power Settings is more universal and easier to implement. AFAIK, PowerToys require an active GUI session > > * User doesn't need active GUI session to run and stop a server. > * It's easy to run remotely via Open SSH as it's built in in WIndows 10+ by Microsoft itself. > * It's flexible, so you know how to change it's easily by yourself and what exact settings you prefer to have. > * As it's a potentially scripted solution and you know exact schedule when it's needed, Windows Scheduler could be used. > * It doesn't break in a hidden way any expectations a user might have. I think we are not talking the same thing. You suggest me to use SSH, so you supposed I am using a remote terminal. I am not. I am using an app that use Ollama's API. So there is no SSH, just http.
Author
Owner

@owenzhao commented on GitHub (May 11, 2024):

Also, I think it is common that a server stops the OS from sleeping. For example, SMB, the file sharing service of the Windows, which is also the preferred file sharing service in macOS. When you play a movie from SMB, the OS runs SMB won't go to sleep as long as you playing the movie. So the SMB must have the ability to stop the OS from sleeping.

What I want is the same. I don't think this is a bad idea. It is just like you don't want the OS to sleep when you are playing a movie on SMB.

<!-- gh-comment-id:2105666225 --> @owenzhao commented on GitHub (May 11, 2024): Also, I think it is common that a server stops the OS from sleeping. For example, SMB, the file sharing service of the Windows, which is also the preferred file sharing service in macOS. When you play a movie from SMB, the OS runs SMB won't go to sleep as long as you playing the movie. So the SMB must have the ability to stop the OS from sleeping. What I want is the same. I don't think this is a bad idea. It is just like you don't want the OS to sleep when you are playing a movie on SMB.
Author
Owner

@eirnym commented on GitHub (May 11, 2024):

SMB is not the same at all. This is a low-level driver. This represents a file system and it's critical for the operation system to provide guarantee that data transferred would be transferred without data losses and all writes would written to the disk.

You have no such guarantee for user space file systems such as sshfs.

<!-- gh-comment-id:2105959266 --> @eirnym commented on GitHub (May 11, 2024): SMB is not the same at all. This is a low-level driver. This represents a file system and it's critical for the operation system to provide guarantee that data transferred would be transferred without data losses and all writes would written to the disk. You have no such guarantee for user space file systems such as sshfs.
Author
Owner

@owenzhao commented on GitHub (May 11, 2024):

SMB is not the same at all. This is a low-level driver. This represents a file system and it's critical for the operation system to provide guarantee that data transferred would be transferred without data losses and all writes would written to the disk.

You have no such guarantee for user space file systems such as sshfs.

You have too many principles, but can you consider the user experience? A naive user, which is me, just think they are the same and should work alike.

<!-- gh-comment-id:2106051290 --> @owenzhao commented on GitHub (May 11, 2024): > SMB is not the same at all. This is a low-level driver. This represents a file system and it's critical for the operation system to provide guarantee that data transferred would be transferred without data losses and all writes would written to the disk. > > You have no such guarantee for user space file systems such as sshfs. You have too many principles, but can you consider the user experience? A naive user, which is me, just think they are the same and should work alike.
Author
Owner

@eirnym commented on GitHub (May 12, 2024):

They are not the same and should not work alike.

A HTTP server is not a system driver on a host OS and should not be considered alike even from an end user perspective. You can install any other HTTP servers and try yourself. Even Docker (paid) doesn't prevent computer go to sleep. (I know there's issue that some users complain that docker prevents computer to sleep, while I don't experience this issue on my systems)

You want a feature you can do as a power user (not even system administrator) if you just switch power settings to another profile.

Proposed solution by me is easy to implement, easy to use, intuitive and universal. You don't need special knowledge to write specific Power Shell scripts, just copy-paste from other projects including mentioned ones or from services like Stack Overflow.

<!-- gh-comment-id:2106157760 --> @eirnym commented on GitHub (May 12, 2024): They are not the same and should not work alike. A HTTP server is not a system driver on a host OS and should not be considered alike even from an end user perspective. You can install any other HTTP servers and try yourself. Even Docker (paid) doesn't prevent computer go to sleep. (I know there's issue that some users complain that docker prevents computer to sleep, while I don't experience this issue on my systems) You want a feature you can do as a power user (not even system administrator) if you just switch power settings to another profile. Proposed solution by me is easy to implement, easy to use, intuitive and universal. You don't need special knowledge to write specific Power Shell scripts, just copy-paste from other projects including mentioned ones or from services like Stack Overflow.
Author
Owner

@owenzhao commented on GitHub (May 13, 2024):

They are just the same. They are the same until you add new rules.

First, you say servers are not apps. Then, you say servers are not the same. So you just want to keep your point, instead of listening. You force me to user power settings, which is totally a different thing. Power setting are set for the global, what I suggest is for the local, specially for the Ollama. Why local should change global? Where are your principles now?

This thing is easy and clear. The system provides API to keep the OS awake. The decision is made by developer to improve user experience. Whether to do depends on if the solution is expected by the user. This is the only rule. Not other rules are needed. Intuitively, if a user expects the app should work, then it is a good solution.

<!-- gh-comment-id:2106444885 --> @owenzhao commented on GitHub (May 13, 2024): They are just the same. They are the same until you add new rules. First, you say servers are not apps. Then, you say servers are not the same. So you just want to keep your point, instead of listening. You force me to user power settings, which is totally a different thing. Power setting are set for the global, what I suggest is for the local, specially for the Ollama. Why local should change global? Where are your principles now? This thing is easy and clear. The system provides API to keep the OS awake. The decision is made by developer to improve user experience. Whether to do depends on if the solution is expected by the user. This is the only rule. Not other rules are needed. Intuitively, if a user expects the app should work, then it is a good solution.
Author
Owner

@eirnym commented on GitHub (May 13, 2024):

  1. How are they the same? You set "rules" that they are the same. Please, ask Google Search (or any other similar) if a HTTP server is the same as SMB service and what is a bad or good practice for keeping machine awake.

  2. Ollama has server component server which you want to run on a windows machine and client you want to run on a separate machine.

  3. That is you propose to set global thing using a non-critical service. Please, don't mess with responsibility of between service and administrator. You're an administrator of your personal computer and you are responsible of how things should be done.

  4. I explained how Ollama works a few times and you probably skipped these parts. At the beginning you asked to keep windows alive per request, which would not a reasonable solution and I explained why.

If change will be per request, your single request will be finished and the next may not start and you won't be happy. Again.

  1. You propose how to change Ollama for your specific task, but forget that others might not want to do that and prefer to set up their systems as they expect system will behave.

For example, let's imagine your proposition has been implemented and another user installed Ollama on a laptop with Windows. Ollama per your request will drain battery as computer won't go to sleep. Or let's imagine places with high electricity bill, people won't be happy that their computer drains their money as it doesn't want to go to sleep when it supposed to.

<!-- gh-comment-id:2106900401 --> @eirnym commented on GitHub (May 13, 2024): 1. How are they the same? You set "rules" that they are the same. Please, ask Google Search (or any other similar) if a HTTP server is the same as SMB service and what is a bad or good practice for keeping machine awake. 2. Ollama has server component server which you want to run on a windows machine and client you want to run on a separate machine. 3. That is you propose to set global thing using a non-critical service. Please, don't mess with responsibility of between service and administrator. You're an administrator of your personal computer and you are responsible of how things should be done. 4. I explained how Ollama works a few times and you probably skipped these parts. At the beginning you asked to keep windows alive per request, which would not a reasonable solution and I explained why. If change will be per request, your single request will be finished and the next may not start and you won't be happy. Again. 5. You propose how to change Ollama for your specific task, but forget that others might not want to do that and prefer to set up their systems as they expect system will behave. For example, let's imagine your proposition has been implemented and another user installed Ollama on a laptop with Windows. Ollama per your request will drain battery as computer won't go to sleep. Or let's imagine places with high electricity bill, people won't be happy that their computer drains their money as it doesn't want to go to sleep when it supposed to.
Author
Owner

@xgdgsc commented on GitHub (Nov 20, 2024):

I fully support the author' s proposal. As it' s valid use case someone wants to share an ollama instance in office LAN for co-workers to use on a laptop with windows hello that goes to sleep fast when the laptop owner take a break. Adding the mode of preventing sleep when tokens are generated or remote chat connections are active would help a lot, both with electricity consumption and user experience.

<!-- gh-comment-id:2487256845 --> @xgdgsc commented on GitHub (Nov 20, 2024): I fully support the author' s proposal. As it' s valid use case someone wants to share an ollama instance in office LAN for co-workers to use on a laptop with windows hello that goes to sleep fast when the laptop owner take a break. Adding the mode of preventing sleep when tokens are generated or remote chat connections are active would help a lot, both with electricity consumption and user experience.
Author
Owner

@owenzhao commented on GitHub (Nov 20, 2024):

I fully support the author' s proposal. As it' s valid use case someone wants to share an ollama instance in office LAN for co-workers to use on a laptop with windows hello that goes to sleep fast when the laptop owner take a break. Adding the mode of preventing sleep when tokens are generated or remote chat connections are active would help a lot, both with electricity consumption and user experience.

I don't believe "a laptop with windows hello that goes to sleep fast when the laptop owner take a break" is a valid example for working as a server. Do you know what is a server? Server means providing constant services. A Server should not break as it wishes even if it provides services for no charge.

<!-- gh-comment-id:2487797783 --> @owenzhao commented on GitHub (Nov 20, 2024): > I fully support the author' s proposal. As it' s valid use case someone wants to share an ollama instance in office LAN for co-workers to use on a laptop with windows hello that goes to sleep fast when the laptop owner take a break. Adding the mode of preventing sleep when tokens are generated or remote chat connections are active would help a lot, both with electricity consumption and user experience. I don't believe "a laptop with windows hello that goes to sleep fast when the laptop owner take a break" is a valid example for working as a server. Do you know what is a server? Server means providing constant services. A Server should not break as it wishes even if it provides services for no charge.
Author
Owner

@molbal commented on GitHub (Nov 20, 2024):

For laptops use something like this: https://learn.microsoft.com/en-us/windows/powertoys/awake

<!-- gh-comment-id:2488077601 --> @molbal commented on GitHub (Nov 20, 2024): For laptops use something like this: https://learn.microsoft.com/en-us/windows/powertoys/awake
Author
Owner

@Snehallaldas commented on GitHub (Dec 11, 2024):

You can create a simple PowerShell script that monitors whether a specific application is running. When the application is active, the script will stop your computer from going to sleep. Once you close the application, it will restore your system's default sleep settings.

Steps:
Write the Script: Open a text editor (like Notepad) and paste the following code. Save the file as PreventSleep.ps1

Replace "YourApplicationName" with the name of the app's process (e.g., "notepad").

$AppName = "YourApplicationName"
$SleepDisabled = $false

while ($true) {
# Check if the application is running.
$AppRunning = Get-Process -Name $AppName -ErrorAction SilentlyContinue

if ($AppRunning) {
    # If the app is running and sleep isn't already disabled, prevent sleep.
    if (-not $SleepDisabled) {
        Write-Output "The application is running. Preventing sleep..."
        powercfg -change -monitor-timeout-ac 0
        powercfg -change -monitor-timeout-dc 0
        $SleepDisabled = $true
    }
} else {
    # If the app isn't running but sleep was disabled, restore defaults.
    if ($SleepDisabled) {
        Write-Output "The application has stopped. Restoring sleep settings..."
        powercfg -restoredefaultschemes
        $SleepDisabled = $false
    }
}

Start-Sleep -Seconds 10 # Wait 10 seconds before checking again.

}

Replace "YourApplicationName" with the name of the application's process. For example, if you want this for Notepad, use notepad.

Run the Script:

Open PowerShell as an Administrator.
Navigate to the folder where you saved the script.
Run the script using the command:
powershell
Copy code
.\PreventSleep.ps1
The script will now monitor your application and manage sleep settings.

Make It Run Automatically: If you want this to work every time you start your computer or open the application:

Use Task Scheduler to run the script on startup or when the application launches.
Alternatively, create a shortcut to the script and run it manually when needed.

This script essentially checks every 10 seconds if the specified app is running. If it finds the app, it keeps the computer awake. Once the app is closed, it restores your default sleep settings. It’s a lightweight and automatic way to handle this without manually toggling any settings.

<!-- gh-comment-id:2533580659 --> @Snehallaldas commented on GitHub (Dec 11, 2024): You can create a simple PowerShell script that monitors whether a specific application is running. When the application is active, the script will stop your computer from going to sleep. Once you close the application, it will restore your system's default sleep settings. **Steps:** Write the Script: Open a text editor (like Notepad) and paste the following code. Save the file as PreventSleep.ps1 ------------------------------------------------------------------------------------------------------------------------------ # Replace **"YourApplicationName"** with the name of the app's process (e.g., "notepad"). $AppName = "YourApplicationName" $SleepDisabled = $false while ($true) { # Check if the application is running. $AppRunning = Get-Process -Name $AppName -ErrorAction SilentlyContinue if ($AppRunning) { # If the app is running and sleep isn't already disabled, prevent sleep. if (-not $SleepDisabled) { Write-Output "The application is running. Preventing sleep..." powercfg -change -monitor-timeout-ac 0 powercfg -change -monitor-timeout-dc 0 $SleepDisabled = $true } } else { # If the app isn't running but sleep was disabled, restore defaults. if ($SleepDisabled) { Write-Output "The application has stopped. Restoring sleep settings..." powercfg -restoredefaultschemes $SleepDisabled = $false } } Start-Sleep -Seconds 10 # Wait 10 seconds before checking again. } --------------------------------------------------------------------------------------------------------------------------------------- Replace "YourApplicationName" with the name of the application's process. For example, if you want this for Notepad, use notepad. **Run the Script:** Open PowerShell as an Administrator. Navigate to the folder where you saved the script. Run the script using the command: powershell Copy code .\PreventSleep.ps1 The script will now monitor your application and manage sleep settings. Make It Run Automatically: If you want this to work every time you start your computer or open the application: Use Task Scheduler to run the script on startup or when the application launches. Alternatively, create a shortcut to the script and run it manually when needed. This script essentially checks every 10 seconds if the specified app is running. If it finds the app, it keeps the computer awake. Once the app is closed, it restores your default sleep settings. It’s a lightweight and automatic way to handle this without manually toggling any settings.
Author
Owner

@owenzhao commented on GitHub (Dec 11, 2024):

You can create a simple PowerShell script that monitors whether a specific application is running. When the application is active, the script will stop your computer from going to sleep. Once you close the application, it will restore your system's default sleep settings.

Steps:

Write the Script: Open a text editor (like Notepad) and paste the following code. Save the file as PreventSleep.ps1

Replace "YourApplicationName" with the name of the app's process (e.g., "notepad").

$AppName = "YourApplicationName" $SleepDisabled = $false

while ($true) { # Check if the application is running. $AppRunning = Get-Process -Name $AppName -ErrorAction SilentlyContinue

if ($AppRunning) {
    # If the app is running and sleep isn't already disabled, prevent sleep.
    if (-not $SleepDisabled) {
        Write-Output "The application is running. Preventing sleep..."
        powercfg -change -monitor-timeout-ac 0
        powercfg -change -monitor-timeout-dc 0
        $SleepDisabled = $true
    }
} else {
    # If the app isn't running but sleep was disabled, restore defaults.
    if ($SleepDisabled) {
        Write-Output "The application has stopped. Restoring sleep settings..."
        powercfg -restoredefaultschemes
        $SleepDisabled = $false
    }
}

Start-Sleep -Seconds 10 # Wait 10 seconds before checking again.

}

Replace "YourApplicationName" with the name of the application's process. For example, if you want this for Notepad, use notepad.

Run the Script:

Open PowerShell as an Administrator. Navigate to the folder where you saved the script. Run the script using the command: powershell Copy code .\PreventSleep.ps1 The script will now monitor your application and manage sleep settings.

Make It Run Automatically: If you want this to work every time you start your computer or open the application:

Use Task Scheduler to run the script on startup or when the application launches. Alternatively, create a shortcut to the script and run it manually when needed.

This script essentially checks every 10 seconds if the specified app is running. If it finds the app, it keeps the computer awake. Once the app is closed, it restores your default sleep settings. It’s a lightweight and automatic way to handle this without manually toggling any settings.

Thanks for your reply. However, this solution won't work on the situation that Ollama working on another machine. To simplified my question. Let's assume you have an application that makes API calls to another computer running Ollama. The purpose of this application is to batch process images by utilizing Ollama to identify the content in those images. This is typically a lengthy process. As a result, it's quite common for the application to keep waiting for Ollama to finish processing while the other computer has already gone to sleep.

<!-- gh-comment-id:2535037851 --> @owenzhao commented on GitHub (Dec 11, 2024): > You can create a simple PowerShell script that monitors whether a specific application is running. When the application is active, the script will stop your computer from going to sleep. Once you close the application, it will restore your system's default sleep settings. > > ## **Steps:** > Write the Script: Open a text editor (like Notepad) and paste the following code. Save the file as PreventSleep.ps1 > # Replace **"YourApplicationName"** with the name of the app's process (e.g., "notepad"). > $AppName = "YourApplicationName" $SleepDisabled = $false > > while ($true) { # Check if the application is running. $AppRunning = Get-Process -Name $AppName -ErrorAction SilentlyContinue > > ``` > if ($AppRunning) { > # If the app is running and sleep isn't already disabled, prevent sleep. > if (-not $SleepDisabled) { > Write-Output "The application is running. Preventing sleep..." > powercfg -change -monitor-timeout-ac 0 > powercfg -change -monitor-timeout-dc 0 > $SleepDisabled = $true > } > } else { > # If the app isn't running but sleep was disabled, restore defaults. > if ($SleepDisabled) { > Write-Output "The application has stopped. Restoring sleep settings..." > powercfg -restoredefaultschemes > $SleepDisabled = $false > } > } > > Start-Sleep -Seconds 10 # Wait 10 seconds before checking again. > ``` > > ## } > Replace "YourApplicationName" with the name of the application's process. For example, if you want this for Notepad, use notepad. > > **Run the Script:** > > Open PowerShell as an Administrator. Navigate to the folder where you saved the script. Run the script using the command: powershell Copy code .\PreventSleep.ps1 The script will now monitor your application and manage sleep settings. > > Make It Run Automatically: If you want this to work every time you start your computer or open the application: > > Use Task Scheduler to run the script on startup or when the application launches. Alternatively, create a shortcut to the script and run it manually when needed. > > This script essentially checks every 10 seconds if the specified app is running. If it finds the app, it keeps the computer awake. Once the app is closed, it restores your default sleep settings. It’s a lightweight and automatic way to handle this without manually toggling any settings. Thanks for your reply. However, this solution won't work on the situation that Ollama working on another machine. To simplified my question. Let's assume you have an application that makes API calls to another computer running Ollama. The purpose of this application is to batch process images by utilizing Ollama to identify the content in those images. This is typically a lengthy process. As a result, it's quite common for the application to keep waiting for Ollama to finish processing while the other computer has already gone to sleep.
Author
Owner

@eirnym commented on GitHub (Dec 11, 2024):

@owenzhao Could you please collaborate why script provided won't work in your case?

Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH)

<!-- gh-comment-id:2536048988 --> @eirnym commented on GitHub (Dec 11, 2024): @owenzhao Could you please collaborate why script provided won't work in your case? Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH)
Author
Owner

@owenzhao commented on GitHub (Dec 11, 2024):

@owenzhao Could you please collaborate why script provided won't work in your case?

Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH)

It does run everywhere. But what if the server running Ollama is not mine? As I may provide the app on the App Store. You suggest me to ask the users to run the script one by one? That will reduce potential users hugely and leading a developer looking for servers other than Ollama as a replacement.

<!-- gh-comment-id:2536907069 --> @owenzhao commented on GitHub (Dec 11, 2024): > @owenzhao Could you please collaborate why script provided won't work in your case? > > Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH) It does run everywhere. But what if the server running Ollama is not mine? As I may provide the app on the App Store. You suggest me to ask the users to run the script one by one? That will reduce potential users hugely and leading a developer looking for servers other than Ollama as a replacement.
Author
Owner

@owenzhao commented on GitHub (Dec 11, 2024):

@owenzhao Could you please collaborate why script provided won't work in your case?

Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH)

Besides, my suggestion is not prevent a computer to sleep if Ollama is running. I want my app is not interrupt after it start working with Ollama. So the condition will be "ollama ps" has outputs. If "ollama ps" is empty, the computer can sleep as it is.

<!-- gh-comment-id:2536919157 --> @owenzhao commented on GitHub (Dec 11, 2024): > @owenzhao Could you please collaborate why script provided won't work in your case? > > Please note, that this script doesn't require remote session and you can run it remotely as well (e.g. via SSH) Besides, my suggestion is not prevent a computer to sleep if Ollama is running. I want my app is not interrupt after it start working with Ollama. So the condition will be "ollama ps" has outputs. If "ollama ps" is empty, the computer can sleep as it is.
Author
Owner

@eirnym commented on GitHub (Dec 12, 2024):

Condition in script provided can be improved to satisfy your needs: to check if process exists and command output satisfy "if processing is running".

Additionally, other power settings can be set to satisfy your personal preferences.

Powershell scripting is powerful enough to satisfy your needs

<!-- gh-comment-id:2539287906 --> @eirnym commented on GitHub (Dec 12, 2024): Condition in script provided can be improved to satisfy your needs: to check if process exists and command output satisfy "if processing is running". Additionally, other power settings can be set to satisfy your personal preferences. Powershell scripting is powerful enough to satisfy your needs
Author
Owner

@Bob2345de commented on GitHub (Feb 14, 2025):

Has someone managed to create a suitable PS script for this?

<!-- gh-comment-id:2659371518 --> @Bob2345de commented on GitHub (Feb 14, 2025): Has someone managed to create a suitable PS script for this?
Author
Owner

@michael-stief commented on GitHub (Mar 5, 2025):

I would also be interested in this feature. My use case is to use Ollama every now and then. I can specify a program/script in my client before a request is sent to Ollama, in my case a Wake-on-LAN packet via internet. My PC wakes up from standby and can compute the response. My PC is a lot more powerful than my laptop, but no high-end machine so the response can take between a few minutes and an hour. My PCs is set to go to standby real fast since I use it only for occasional requests and gaming when I'm at home.

Monitoring the PID doesn't really help in my use case. I'd have to connect to my PC with VPN and RDP to manually start and stop the service each time I ask a question. Also since I don't know how long it will take to generate the answer I'd like to do something else, check later for the answer and be sure it was fully computed and received. My PC shouldn't go into standby in the meantime while it is still working on it. But I also want my PC to go to standby automatically how I configured it in the energy options in Windows as soon as the question is processed. If I need my PC again for another question and the pause between them are larger than the configured standby time another magic packet automatically sent before my question will take care of it.

The suggestion from owenzhao is perfectly valid in my opinion. As long as Ollama is working on a response it should prevent standby since it's uncertain how long the response will take. After it's finished, it should allow the PC to go into standby as usual.

<!-- gh-comment-id:2701956118 --> @michael-stief commented on GitHub (Mar 5, 2025): I would also be interested in this feature. My use case is to use Ollama every now and then. I can specify a program/script in my client before a request is sent to Ollama, in my case a Wake-on-LAN packet via internet. My PC wakes up from standby and can compute the response. My PC is a lot more powerful than my laptop, but no high-end machine so the response can take between a few minutes and an hour. My PCs is set to go to standby real fast since I use it only for occasional requests and gaming when I'm at home. Monitoring the PID doesn't really help in my use case. I'd have to connect to my PC with VPN and RDP to manually start and stop the service each time I ask a question. Also since I don't know how long it will take to generate the answer I'd like to do something else, check later for the answer and be sure it was fully computed and received. My PC shouldn't go into standby in the meantime while it is still working on it. But I also want my PC to go to standby automatically how I configured it in the energy options in Windows as soon as the question is processed. If I need my PC again for another question and the pause between them are larger than the configured standby time another magic packet automatically sent before my question will take care of it. The suggestion from owenzhao is perfectly valid in my opinion. As long as Ollama is working on a response it should prevent standby since it's uncertain how long the response will take. After it's finished, it should allow the PC to go into standby as usual.
Author
Owner

@eirnym commented on GitHub (Mar 6, 2025):

@michael-stief Could you tell if I understood your correctly. You log into your PC, asking ollama for a single answer, then keep it sleeping?

If my assumption is correct, then I see it as scenario in a script below. It's written in Zsh, but is applicable to your situation as well.

$ ollama serve # start the server (at some point before, or just for a query) — this may run 
$ ollama run ... # run a long query
# wait for Ollama finish their job
# take work back to your local computer
# free computer to have a sleep

Checking ollama ps instead of just plain PID would help in your situation. The script logic won't change much. In zsh it would be something like this: ollama ps | wc -l and do something with a number.

<!-- gh-comment-id:2702507830 --> @eirnym commented on GitHub (Mar 6, 2025): @michael-stief Could you tell if I understood your correctly. You log into your PC, asking `ollama` for a single answer, then keep it sleeping? If my assumption is correct, then I see it as scenario in a script below. It's written in Zsh, but is applicable to your situation as well. ```zsh $ ollama serve # start the server (at some point before, or just for a query) — this may run $ ollama run ... # run a long query # wait for Ollama finish their job # take work back to your local computer # free computer to have a sleep ``` Checking `ollama ps` instead of just plain PID would help in your situation. The script logic won't change much. In `zsh` it would be something like this: `ollama ps | wc -l` and do something with a number.
Author
Owner

@eirnym commented on GitHub (Mar 6, 2025):

@Bob2345de What from the script above doesn't work in your situation?

<!-- gh-comment-id:2702509412 --> @eirnym commented on GitHub (Mar 6, 2025): @Bob2345de What from the script above doesn't work in your situation?
Author
Owner

@Alexious-sh commented on GitHub (Jul 28, 2025):

Come on! Did anyone from "scripters" ever used ollama on a remote machine? No one runs ollama run... through SSH or whatever. Most of the people using the API, commenting from open-webui or any other system. It doesn't spawn any extra process you could monitor externally. That's why, I think, it's an ollama's responsibility to keep a wakelock while LLM is active. Especially, given that it shouldn't be so hard to implement.

<!-- gh-comment-id:3126411859 --> @Alexious-sh commented on GitHub (Jul 28, 2025): Come on! Did anyone from "scripters" ever used ollama on a remote machine? No one runs `ollama run...` through SSH or whatever. Most of the people using the API, commenting from open-webui or any other system. It doesn't spawn any extra process you could monitor externally. That's why, I think, it's an ollama's responsibility to keep a wakelock while LLM is active. Especially, given that it shouldn't be so hard to implement.
Author
Owner

@molbal commented on GitHub (Jul 28, 2025):

Following that logic @Alexious-sh all other servers should maintain their own wake locks.

Ollama shouldn't be responsible for the environment it's running in.

<!-- gh-comment-id:3126475736 --> @molbal commented on GitHub (Jul 28, 2025): Following that logic @Alexious-sh all other servers should maintain their own wake locks. Ollama shouldn't be responsible for the environment it's running in.
Author
Owner

@eirnym commented on GitHub (Jul 28, 2025):

@Alexious-sh if you use web api, use one of the method above to keep machine awake while server is running.

<!-- gh-comment-id:3127034700 --> @eirnym commented on GitHub (Jul 28, 2025): @Alexious-sh if you use web api, use one of the method above to keep machine awake while server is running.
Author
Owner

@Alexious-sh commented on GitHub (Sep 1, 2025):

@molbal This is how Windows apps usually do. Unfortunately, non-server Windows systems doesn't have many built-in tools to achieve something like systemd sockets provide on Linux. E.g. I currently have a middleware proxy service running on a dedicated low-power machine, which sends a Wake-on-LAN packet to my desktop if it's sleeping and then proxies everything to the Ollama running there. And the only problem now is that PC could fall asleep in the middle of interaction with Ollama.

@eirnym Which one? Using "numerous of unspoken ways to theoretically do something" or tracking the PID of the always running ollama serve process? None of them helped, unfortunately.

<!-- gh-comment-id:3242606938 --> @Alexious-sh commented on GitHub (Sep 1, 2025): @molbal This is how Windows apps usually do. Unfortunately, non-server Windows systems doesn't have many built-in tools to achieve something like systemd sockets provide on Linux. E.g. I currently have a middleware proxy service running on a dedicated low-power machine, which sends a Wake-on-LAN packet to my desktop if it's sleeping and then proxies everything to the Ollama running there. And the only problem now is that PC could fall asleep in the middle of interaction with Ollama. @eirnym Which one? Using "numerous of unspoken ways to theoretically do something" or tracking the PID of the always running `ollama serve` process? None of them helped, unfortunately.
Author
Owner

@eirnym commented on GitHub (Sep 1, 2025):

@Alexious-sh Thank you for sharing your setup.

Could you please share your experience how exactly you've implemented and didn't worked. Specific implementation would help others to help and others to use.

<!-- gh-comment-id:3242860021 --> @eirnym commented on GitHub (Sep 1, 2025): @Alexious-sh Thank you for sharing your setup. Could you please share your experience how exactly you've implemented and didn't worked. Specific implementation would help others to help and others to use.
Author
Owner

@tdbe commented on GitHub (Oct 26, 2025):

Despite the abundance of common use presented, seems a few ollama contributors have developed cutting edge mental gymnastics for why they like their computer turning off to save power while it's in the middle of serving.

Here's the expected solution until the stegosauruses go away: You're probably running ollama through a js web client like this, something you can edit/extend. So:

Just make every Send of the prompt window also send a command that resets the idle timer of the server OS.

Need to use a custom (python) server for this, and start it after logon. (An apache php's script exec invoke or other GUI-less environments afaics forbid access to any idle reset events.)

Using key press events (simplest reliable option), with pyautogui (but nircmd also works).

Server.py:

from http.server import BaseHTTPRequestHandler, HTTPServer
import pyautogui
import json

class RequestHandler(BaseHTTPRequestHandler):
    def _set_headers(self, status_code=200):
        self.send_response(status_code)
        self.send_header('Content-type', 'text/html')
        self.send_header('Access-Control-Allow-Origin', '*')
        self.send_header('Access-Control-Allow-Methods', 'POST, OPTIONS')
        self.send_header('Access-Control-Allow-Headers', 'Content-Type')
        self.end_headers()

    def do_OPTIONS(self):
        self._set_headers()
        
    def do_POST(self):
        content_length = int(self.headers['Content-Length'])
        post_data = self.rfile.read(content_length)
        data = json.loads(post_data.decode('utf-8'))

        action = data.get('action')
        if action == 'press_key':
            pyautogui.press('ctrl')
            self._set_headers()
            self.wfile.write(b'Key pressed successfully')
        else:
            self._set_headers(400)
            self.wfile.write(b'Invalid action')

def run(server_class=HTTPServer, handler_class=RequestHandler, port=69420):
    server_address = ('', port)
    httpd = server_class(server_address, handler_class)
    print(f'Starting server on port {port}...')
    httpd.serve_forever()

if __name__ == '__main__':
    run()

Client js usage example (also call this when you press Send):

async function pressKeyToResetIdle(url = "http://192.168.12.34:69420") {
	const data = {
		action: 'press_key'
	};

	try {
		const response = await fetch(url, {
			method: 'POST',
			headers: {
				'Content-Type': 'application/json',
			},
			body: JSON.stringify(data)
		});

		if (response.ok) {
			const result = await response.text();
			console.log(result);
		} else {
			console.error('Error:', response.statusText);
		}
	} catch (error) {
		console.error('Error:', error);
	}
}

This will work cross-domain on your LAN. You can now WoL and use ollama free from the mushy chew of the stegosaurus.

<!-- gh-comment-id:3447983709 --> @tdbe commented on GitHub (Oct 26, 2025): Despite the abundance of common use presented, seems a few ollama contributors have developed cutting edge mental gymnastics for why they like their computer turning off to save power while it's in the middle of serving. Here's the expected solution until the stegosauruses go away: You're probably running ollama through a js web client [like this](https://github.com/ollama-ui), something you can edit/extend. So: Just make every `Send` of the prompt window also send a command that `resets the idle timer` of the server OS. Need to use a custom (python) server for this, and start it after logon. (An apache php's script exec invoke or other GUI-less environments afaics forbid access to any idle reset events.) Using key press events (simplest reliable option), with pyautogui (but nircmd [also](https://nircmd.nirsoft.net/sendkey.html) [works](https://nircmd.nirsoft.net/sendkeypress.html)). Server.py: ``` from http.server import BaseHTTPRequestHandler, HTTPServer import pyautogui import json class RequestHandler(BaseHTTPRequestHandler): def _set_headers(self, status_code=200): self.send_response(status_code) self.send_header('Content-type', 'text/html') self.send_header('Access-Control-Allow-Origin', '*') self.send_header('Access-Control-Allow-Methods', 'POST, OPTIONS') self.send_header('Access-Control-Allow-Headers', 'Content-Type') self.end_headers() def do_OPTIONS(self): self._set_headers() def do_POST(self): content_length = int(self.headers['Content-Length']) post_data = self.rfile.read(content_length) data = json.loads(post_data.decode('utf-8')) action = data.get('action') if action == 'press_key': pyautogui.press('ctrl') self._set_headers() self.wfile.write(b'Key pressed successfully') else: self._set_headers(400) self.wfile.write(b'Invalid action') def run(server_class=HTTPServer, handler_class=RequestHandler, port=69420): server_address = ('', port) httpd = server_class(server_address, handler_class) print(f'Starting server on port {port}...') httpd.serve_forever() if __name__ == '__main__': run() ``` Client js usage example (also call this when you press Send): ``` async function pressKeyToResetIdle(url = "http://192.168.12.34:69420") { const data = { action: 'press_key' }; try { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }); if (response.ok) { const result = await response.text(); console.log(result); } else { console.error('Error:', response.statusText); } } catch (error) { console.error('Error:', error); } } ``` This will work cross-domain on your LAN. You can now WoL and use ollama free from the mushy chew of the stegosaurus.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#2529