#!/bin/bash # To be run by user wbg to create the pod and container with # Open WebUI and to create the systemd service # Open WebUI releases: https://github.com/open-webui/open-webui/releases # Environment variables POD_NAME='openwebui_pod' CTR_NAME='openwebui_ctr' IMAGE='ghcr.io/open-webui/open-webui:v0.8.12-cuda' # IMAGE='ghcr.io/open-webui/open-webui:git-9ae06a3' HOST_LOCAL_IP='127.0.0.1' openwebui_pod_HOST_PORT='8080' AIGPU_HOST_PORT='8081' NET_OPTS='slirp4netns:allow_host_loopback=true' BIND_DIR="$HOME/.local/share/$POD_NAME" BACKEND_DIR="$BIND_DIR/backend_data" USER_SYSTEMD_DIR="$HOME/.config/systemd/user" # Prepare directories mkdir -p "$BACKEND_DIR" "$USER_SYSTEMD_DIR" # Create pod if not yet existing if ! podman pod exists "$POD_NAME"; then podman pod create -n "$POD_NAME" \ --network "$NET_OPTS" \ -p ${HOST_LOCAL_IP}:${openwebui_pod_HOST_PORT}:${openwebui_pod_HOST_PORT} echo "Pod '$POD_NAME' created (rc=$?)" else echo "Pod '$POD_NAME' already exists." fi # Open WebUI container # Remove old container podman rm -f "$CTR_NAME" # New container podman run -d --name "$CTR_NAME" --pod "$POD_NAME" \ -e OLLAMA_BASE_URL=10.0.2.2:"$AIGPU_HOST_PORT" \ -v "$BACKEND_DIR":/app/backend/data \ "$IMAGE" echo "Started $CTR_NAME container (rc=$?)" # Generate systemd service files cd "$USER_SYSTEMD_DIR" podman generate systemd --files --new --name "$POD_NAME" echo "Generated systemd service files (rc=$?)" # Stop & remove live pod and containers podman pod stop --ignore --time 15 "$POD_NAME" podman pod rm -f --ignore "$POD_NAME" if podman pod exists "$POD_NAME"; then echo "ERROR: Pod $POD_NAME still exists." exit 1 else echo "Stopped & removed live pod $POD_NAME and containers" fi # Enable systemd service systemctl --user daemon-reload systemctl --user enable --now "pod-${POD_NAME}.service" echo "Enabled systemd service pod-${POD_NAME}.service (rc=$?)" echo "Status: systemctl --user status pod-${POD_NAME}.service" echo "View logs: journalctl --user -u pod-${POD_NAME}.service -f" systemctl --user enable --now "container-${CTR_NAME}.service" echo "Enabled systemd service container-${CTR_NAME}.service (rc=$?)" echo "Status: systemctl --user status container-${CTR_NAME}.service" echo "View logs: journalctl --user -u container-${CTR_NAME}.service -f"