Skip to content

Commit

Permalink
Attempt to trap SIGTERM to close open-webui container upon exiting (b…
Browse files Browse the repository at this point in the history
…ut failing)
  • Loading branch information
tokk-nv committed May 16, 2024
1 parent 73ff55a commit 8a7772e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
10 changes: 8 additions & 2 deletions packages/llm/ollama/Dockerfile.open-webui
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
ARG BASE_IMAGE
FROM ${BASE_IMAGE}

CMD /start_ollama && \
docker run -it --rm --network=host --add-host=host.docker.internal:host-gateway ghcr.io/open-webui/open-webui:main
COPY start_ollama_openwebui /

# ENTRYPOINT /start_ollama && \
# /start_open_webui && \
# /stop_open_webui_upon_exit & \
# /bin/bash

ENTRYPOINT ["/start_ollama_openwebui"]
2 changes: 1 addition & 1 deletion packages/llm/ollama/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

open_webui['name'] = 'ollama:open-webui'
open_webui['dockerfile'] = 'Dockerfile.open-webui'
open_webui['depends'] = ['ollama:main']
open_webui['depends'] = ['ollama:main', 'docker']

del open_webui['alias']

Expand Down
43 changes: 43 additions & 0 deletions packages/llm/ollama/start_ollama_openwebui
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
: "${OLLAMA_LOGS:=/data/logs/ollama.log}"
: "${OPEN_WEBUI_PORT:=8080}"
: "${OPEN_WEBUI_LOGS:=/data/logs/openw-webui.log}"


stop_container_openwebui() {
echo ">>> docker stop open-webui "
docker stop open-webui
exit
}

trap "stop_container_openwebui; echo '[start] SIGTERM received'; exit" TERM

### Ollama server

printf "\n >>>>>>> Starting ollama server\n\n"

/bin/bash -c "/bin/ollama serve &> $OLLAMA_LOGS" &

timeout 5 tail -f $OLLAMA_LOGS

printf "\nOLLAMA_MODELS ${OLLAMA_MODELS}\n"
printf "OLLAMA_LOGS ${OLLAMA_LOGS}\n"

printf "\nollama server is now started, and you can run commands here like 'ollama run llama3'\n\n"

### Open WebUI

server_url="http://$(hostname -I | cut -d' ' -f1):${OPEN_WEBUI_PORT}"

printf "\n >>>>>>> Starting Open WebUI\n\n"

echo "/bin/bash -c \"docker run --rm --network=host -e OLLAMA_BASE_URL=http://127.0.0.1:11434 -e DOCS_DIR=/data/documents -v /home/jetson/jetson-containers_tokknv/data/documents/:/data/documents/ --name open-webui ghcr.io/open-webui/open-webui:dev &> $OPEN_WEBUI_LOGS\" &"
/bin/bash -c "docker run --rm --network=host -e OLLAMA_BASE_URL=http://127.0.0.1:11434 -e DOCS_DIR=/data/documents -v /home/jetson/jetson-containers_tokknv/data/documents/:/data/documents/ --name open-webui ghcr.io/open-webui/open-webui:dev &> $OPEN_WEBUI_LOGS" &

timeout 5 tail -f $OPEN_WEBUI_LOGS

printf "\nOpen WebUI is now started\n\n"
printf "Open WebUI URL: $server_url \n"
printf "Open WebUI logs: ${OPEN_WEBUI_LOGS}\n\n"

/bin/bash; stop_container_openwebui

0 comments on commit 8a7772e

Please sign in to comment.