[GH-ISSUE #9169] ollama server (start|stop|logs) #31729

Open
opened 2026-04-22 12:27:02 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @abitrolly on GitHub (Feb 17, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/9169

Many ppl ask how to stop ollama.

There are many ways to control ollama server daemon outside ollama, and ideally if ollama start or ollama stop fails, it could suggest what to do, so that every failure is actionable. Right now there is no stop command, so no guess or hint to user is possible.

So ollama should somehow know that it is started itself. For that, it needs to leave some trace that it started. Maybe some JSON file in well-known location that describes what was started and when. If there is no such file, but somebody is listening and it is ollama too, maybe first ollama can say that it doesn't know who started it, and it is better if it won't bring it down (and it probably couldn't anyway).

To stop the server, maybe it is not a good idea to do this with web request. Probably. Because then user scripts can bring it down. Probably it is better to stop it using some other communication way. Can go programs talk to each other? Like discover that the program is running (using JSON file) and send it a message, like Hello?

server logs could also be a good addition to automate log hunting quest described in https://github.com/ollama/ollama/blob/main/docs/troubleshooting.md#how-to-troubleshoot-issues

And that means that ollama serve will have to be replaced with ollama server start, which is longer.

WDYT? 👍 or 👎

Originally created by @abitrolly on GitHub (Feb 17, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/9169 Many ppl [ask how to stop](https://github.com/ollama/ollama/issues/690) `ollama`. There are many ways to control `ollama` server daemon outside `ollama`, and ideally if `ollama start` or `ollama stop` fails, it could suggest what to do, so that every failure is actionable. Right now there is no `stop` command, so no guess or hint to user is possible. So `ollama` should somehow know that it is started itself. For that, it needs to leave some trace that it started. Maybe some JSON file in well-known location that describes what was started and when. If there is no such file, but somebody is listening and it is `ollama` too, maybe first `ollama` can say that it doesn't know who started it, and it is better if it won't bring it down (and it probably couldn't anyway). To `stop` the server, maybe it is not a good idea to do this with web request. Probably. Because then user scripts can bring it down. Probably it is better to `stop` it using some other communication way. Can `go` programs talk to each other? Like discover that the program is running (using JSON file) and send it a message, like Hello? `server logs` could also be a good addition to automate log hunting quest described in https://github.com/ollama/ollama/blob/main/docs/troubleshooting.md#how-to-troubleshoot-issues And that means that `ollama serve` will have to be replaced with `ollama server start`, which is longer. WDYT? 👍 or 👎
GiteaMirror added the feature request label 2026-04-22 12:27:02 -05:00
Author
Owner

@webdev23 commented on GitHub (Feb 20, 2025):

curl -s http://localhost:11434/api/generate -d '{"model": "'$(ollama ps | tail -n1 | cut -d ' ' -f1 )'", "keep_alive": 0}'

You should get:
.... "done_reason":"unload"

<!-- gh-comment-id:2670049414 --> @webdev23 commented on GitHub (Feb 20, 2025): `curl -s http://localhost:11434/api/generate -d '{"model": "'$(ollama ps | tail -n1 | cut -d ' ' -f1 )'", "keep_alive": 0}'` You should get: .... "done_reason":"unload"
Author
Owner

@abitrolly commented on GitHub (Feb 20, 2025):

@webdev23 that will unload the model, but I doubt it will stop the server.

<!-- gh-comment-id:2671334016 --> @abitrolly commented on GitHub (Feb 20, 2025): @webdev23 [that](https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion) will unload the model, but I doubt it will stop the server.
Author
Owner

@webdev23 commented on GitHub (Feb 20, 2025):

That is related to Linux, and if all these things have to be documented and handled in every programs, the docs will be 400 pages.

Check service
sudo systemctl status ollama

Stop or Start
sudo systemctl stop ollama

Run permanenly as daemon enable/disable
sudo systemctl enable ollama

Kill program running on tcp port 11434:
fuser -k 11434/tcp

Kill PID:
sudo kill -9 $(ps aux | grep ollama | head -n1 | cut -d ' ' -f4)

Just free the VRAM
curl -s http://localhost:11434/api/generate -d '{"model": "'$(ollama ps | tail -n1 | cut -d ' ' -f1 )'", "keep_alive": 0}'

<!-- gh-comment-id:2672978912 --> @webdev23 commented on GitHub (Feb 20, 2025): That is related to Linux, and if all these things have to be documented and handled in every programs, the docs will be 400 pages. Check service `sudo systemctl status ollama` Stop or Start `sudo systemctl stop ollama` Run permanenly as daemon enable/disable `sudo systemctl enable ollama` Kill program running on tcp port 11434: `fuser -k 11434/tcp ` Kill PID: `sudo kill -9 $(ps aux | grep ollama | head -n1 | cut -d ' ' -f4)` Just free the VRAM `curl -s http://localhost:11434/api/generate -d '{"model": "'$(ollama ps | tail -n1 | cut -d ' ' -f1 )'", "keep_alive": 0}'`
Author
Owner

@webdev23 commented on GitHub (Feb 21, 2025):

Check logs in realtime:

sudo journalctl -f | grep ollama

<!-- gh-comment-id:2672989698 --> @webdev23 commented on GitHub (Feb 21, 2025): Check logs in realtime: `sudo journalctl -f | grep ollama`
Author
Owner

@abitrolly commented on GitHub (Feb 21, 2025):

@webdev23 how to get the PID of ollama serve that is executed in the background? For cases like

  1. start server
  2. pull a model
  3. stop server
<!-- gh-comment-id:2673252668 --> @abitrolly commented on GitHub (Feb 21, 2025): @webdev23 how to get the PID of `ollama serve` that is executed in the background? For cases like 1. start server 2. pull a model 3. stop server
Author
Owner

@abitrolly commented on GitHub (Feb 21, 2025):

@web123 also how to get logs just for the (failing) pull into file or editor (with my shortcuts and plugins)? With start run stop I can just redirect the output, but with journalctl I have no idea, and also I don't want read the logs with sudo.

<!-- gh-comment-id:2673259463 --> @abitrolly commented on GitHub (Feb 21, 2025): @web123 also how to get logs just for the (failing) pull into file or editor (with my shortcuts and plugins)? With `start run stop` I can just redirect the output, but with `journalctl` I have no idea, and also I don't want read the logs with `sudo`.
Author
Owner

@webdev23 commented on GitHub (Feb 21, 2025):

As shown in the subcommand: ps aux | grep ollama | head -n1 | cut -d ' ' -f4

In should output the PID (2nd column), and the exact syntax of that cut command may vary.

Since it's just an extract of the very useful command ps aux , you might have to refine this.

You could use programs like topas well

Or kill by name: sudo pkill -x 'ollama*'


Right, accessing logs this way require sudo, there must be another way, unknown to me.

Output all logs in ~/my_ollama_logs.txt` (could be huge)

sudo journalctl --no-pager | grep ollama > ~/my_ollama_logs.txt

Last 100 lines containing "ollama":

sudo journalctl -n 100 --no-pager | grep ollama > ~/my_ollama_logs.txt


For each use cases you have, write a script `ollama_stop``, set it executable and put it in your favorite PATH (~/.local/bin or so) as declared in your .bashrc or similar rc file in your home, depending your shell.

So later you could just type: ollama_stop , or whatever else.

👍

<!-- gh-comment-id:2673983648 --> @webdev23 commented on GitHub (Feb 21, 2025): As shown in the subcommand: `ps aux | grep ollama | head -n1 | cut -d ' ' -f4` In should output the PID (2nd column), and the exact syntax of that cut command may vary. Since it's just an extract of the very useful command `ps aux `, you might have to refine this. You could use programs like `top`as well Or kill by name: `sudo pkill -x 'ollama*'` --- Right, accessing logs this way require sudo, there must be another way, unknown to me. Output all logs in ~/my_ollama_logs.txt` (could be huge) `sudo journalctl --no-pager | grep ollama > ~/my_ollama_logs.txt` Last 100 lines containing "ollama": `sudo journalctl -n 100 --no-pager | grep ollama > ~/my_ollama_logs.txt` --- For each use cases you have, write a script `ollama_stop``, set it executable and put it in your favorite PATH (~/.local/bin or so) as declared in your .bashrc or similar rc file in your home, depending your shell. So later you could just type: `ollama_stop` , or whatever else. 👍
Author
Owner

@abitrolly commented on GitHub (Feb 21, 2025):

@webdev23 I appreciate your support efforts. And still I have to admit that these hacks and workarounds don't make ollama easier to use. They can not be even reliably scripted.

<!-- gh-comment-id:2674002307 --> @abitrolly commented on GitHub (Feb 21, 2025): @webdev23 I appreciate your support efforts. And still I have to admit that these hacks and workarounds don't make `ollama` easier to use. They can not be even reliably scripted.
Author
Owner

@webdev23 commented on GitHub (Feb 21, 2025):

Sure. I understand. In my opinion, it's a good thing, because it's very easy as a developer to fall into hooking all this in your program and documentation, but in reality, it just introduce potential bugs. All machines aren't exactly handling things the same way, and to handle this as shown here, while unrelated to the main purpose of the program, would require a lot of efforts to maintain. That's why the Linux way is greater, while difficult to catch, what you learnt here could be applied to many other programs.

Later you will write your own service files directly.

Good luck.

<!-- gh-comment-id:2674016055 --> @webdev23 commented on GitHub (Feb 21, 2025): Sure. I understand. In my opinion, it's a good thing, because it's very easy as a developer to fall into hooking all this in your program and documentation, but in reality, it just introduce potential bugs. All machines aren't exactly handling things the same way, and to handle this as shown here, while unrelated to the main purpose of the program, would require a lot of efforts to maintain. That's why the Linux way is greater, while difficult to catch, what you learnt here could be applied to many other programs. Later you will write your own service files directly. Good luck.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#31729