[GH-ISSUE #3341] When is ollama serve ready - for use in scripts? #79736

Open
opened 2026-05-09 06:45:54 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @alexellis on GitHub (Mar 25, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3341

What are you trying to do?

I want to start ollama serve in the background for automation purposes, and then be able to run something like ollama ready which would block until the serve has loaded.

I see this take up to 5 seconds with an Nvidia 3060.

How should we solve this?

ollama ready would be ideal or ollama serve --ready or similar CLI command. Having a REST endpoint could work, but would mean writing a lot of bash loops which can be fragile.

What is the impact of not solving this?

Having to use ollama serve & followed by sleep 5 and that not working some of the time.

Anything else?

I couldn't find anything in the docs that talks about this, but if there is a mechanism for this already, I'd be happy to try it out.

Here's a blog post showing ollama being automated with bash in GitHub Actions, with a GPU attached:

https://actuated.dev/blog/ollama-in-github-actions

Originally created by @alexellis on GitHub (Mar 25, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3341 ### What are you trying to do? I want to start ollama serve in the background for automation purposes, and then be able to run something like `ollama ready` which would block until the serve has loaded. I see this take up to 5 seconds with an Nvidia 3060. ### How should we solve this? `ollama ready` would be ideal or `ollama serve --ready` or similar CLI command. Having a REST endpoint could work, but would mean writing a lot of bash loops which can be fragile. ### What is the impact of not solving this? Having to use `ollama serve &` followed by `sleep 5` and that not working some of the time. ### Anything else? I couldn't find anything in the docs that talks about this, but if there is a mechanism for this already, I'd be happy to try it out. Here's a blog post showing ollama being automated with bash in GitHub Actions, with a GPU attached: https://actuated.dev/blog/ollama-in-github-actions
GiteaMirror added the feature request label 2026-05-09 06:45:54 -05:00
Author
Owner

@Kreijstal commented on GitHub (Mar 25, 2024):

so a sync block of ollama serve

<!-- gh-comment-id:2017749635 --> @Kreijstal commented on GitHub (Mar 25, 2024): so a sync block of ollama serve
Author
Owner

@alexellis commented on GitHub (Mar 25, 2024):

How would that look in bash?

I can't see how we could run additional commands if we were permanently blocked on ollama serve?

Screenshot from 2024-03-25 11-08-55

The sleep is not deterministic so it's starting to generate misc errors.

<!-- gh-comment-id:2017754269 --> @alexellis commented on GitHub (Mar 25, 2024): How would that look in bash? I can't see how we could run additional commands if we were permanently blocked on ollama serve? ![Screenshot from 2024-03-25 11-08-55](https://github.com/ollama/ollama/assets/6358735/4006167d-aaba-4713-a8bb-2a0f7e010c7c) The sleep is not deterministic so it's starting to generate misc errors.
Author
Owner

@alexellis commented on GitHub (Mar 25, 2024):

That sounds like an awful lot of work and repetition in bash.

I would suggest that the ollama team should add this as a Go command or flag and it'd be a very helpful addition.

The ollama serve command should ideally have a --daemonise flag too.

@Kreijstal are you a maintainer/team member? I wasn't sure from your GH profile

<!-- gh-comment-id:2017814362 --> @alexellis commented on GitHub (Mar 25, 2024): That sounds like an awful lot of work and repetition in bash. I would suggest that the ollama team should add this as a Go command or flag and it'd be a very helpful addition. The `ollama serve` command should ideally have a `--daemonise` flag too. @Kreijstal are you a maintainer/team member? I wasn't sure from your GH profile
Author
Owner

@Kreijstal commented on GitHub (Mar 25, 2024):

That sounds like an awful lot of work and repetition in bash.

I would suggest that the ollama team should add this as a Go command or flag and it'd be a very helpful addition.

The ollama serve command should ideally have a --daemonise flag too.

@Kreijstal are you a maintainer/team member? I wasn't sure from your GH profile

no just user

<!-- gh-comment-id:2017834907 --> @Kreijstal commented on GitHub (Mar 25, 2024): > That sounds like an awful lot of work and repetition in bash. > > I would suggest that the ollama team should add this as a Go command or flag and it'd be a very helpful addition. > > The `ollama serve` command should ideally have a `--daemonise` flag too. > > @Kreijstal are you a maintainer/team member? I wasn't sure from your GH profile no just user
Author
Owner

@pdevine commented on GitHub (Mar 25, 2024):

Hey @alexellis! For the endpoint solution you mentioned, you should be able to curl localhost:11434 and it will only respond w/ a 200 if the server is up and running.

<!-- gh-comment-id:2018381884 --> @pdevine commented on GitHub (Mar 25, 2024): Hey @alexellis! For the endpoint solution you mentioned, you should be able to `curl localhost:11434` and it will only respond w/ a 200 if the server is up and running.
Author
Owner

@remy415 commented on GitHub (Mar 25, 2024):

@alexellis In order to run something as a "daemon", you need to have some kind of service manager in your OS. In Linux, which seems to be the environment you're asking about, this is commonly one of initd, sysv, or systemd. You also could technically use Docker or Kubernetes as a "daemon" in a way, but that is out of scope here.

Without some kind of service manager, the only way to run something as a daemon is to mybinary &, nohup mybinary, tmux, etc, so that it runs without capturing your current terminal.

Does your platform have something like systemd on it? If so, just reference the ollama install script to set it up as a service and go to town.

Additionally, did you see this part of the article you mentioned:
image

Did you try using the time curl -i localhost:11434 command referenced there as a blocker agent?

<!-- gh-comment-id:2018850144 --> @remy415 commented on GitHub (Mar 25, 2024): @alexellis In order to run something as a "daemon", you need to have some kind of service manager in your OS. In Linux, which seems to be the environment you're asking about, this is commonly one of `initd`, `sysv`, or `systemd`. You also could technically use Docker or Kubernetes as a "daemon" in a way, but that is out of scope here. Without some kind of service manager, the only way to run something as a daemon is to `mybinary &`, `nohup mybinary`, `tmux`, etc, so that it runs without capturing your current terminal. Does your platform have something like `systemd` on it? If so, just reference the ollama install script to set it up as a service and go to town. Additionally, did you see this part of the article you mentioned: ![image](https://github.com/ollama/ollama/assets/105550370/c1ee6d14-c814-4f54-9c03-ed9dac5150d1) Did you try using the `time curl -i localhost:11434` command referenced there as a blocker agent?
Author
Owner

@alexellis commented on GitHub (Mar 27, 2024):

The curl fails if it follows ollama serve, due to the port not being open immediately. A sleep of a few seconds gives enough time until the port is open.

<!-- gh-comment-id:2022683782 --> @alexellis commented on GitHub (Mar 27, 2024): The curl fails if it follows ollama serve, due to the port not being open immediately. A sleep of a few seconds gives enough time until the port is open.
Author
Owner

@alexellis commented on GitHub (Jun 5, 2024):

@royjhan did you have any further thoughts on the thread?

The curl fails if it follows ollama serve due to the port not being opened immediately.. a sleep is required which is liable to be too long or to fail.

<!-- gh-comment-id:2150951771 --> @alexellis commented on GitHub (Jun 5, 2024): @royjhan did you have any further thoughts on the thread? The curl fails if it follows `ollama serve` due to the port not being opened immediately.. a sleep is required which is liable to be too long or to fail.
Author
Owner

@codefromthecrypt commented on GitHub (Sep 19, 2024):

I'd suggest this path, which seems to work for me alright. If folks are keen maybe we can help close out this issue so folks can reserve energy?

      - name: Start Ollama
        run: |
            # Run the background, in a way that survives to the next step
            nohup ollama serve > ollama.log 2>&1 &
            # Block using the ready endpoint
            time curl --retry 5 --retry-connrefused --retry-delay 0 -sf http://localhost:11434
<!-- gh-comment-id:2360577772 --> @codefromthecrypt commented on GitHub (Sep 19, 2024): I'd suggest this path, which seems to work for me alright. If folks are keen maybe we can help close out this issue so folks can reserve energy? ```yaml - name: Start Ollama run: | # Run the background, in a way that survives to the next step nohup ollama serve > ollama.log 2>&1 & # Block using the ready endpoint time curl --retry 5 --retry-connrefused --retry-delay 0 -sf http://localhost:11434 ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#79736