Repository navigation
Expand file tree
/
Copy pathopen-webui_mgr-cli_v0.5.sh
More file actions
221 lines (184 loc) · 4.9 KB
/
Copy pathopen-webui_mgr-cli_v0.5.sh
File metadata and controls
221 lines (184 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# =============================================================================
# Open-WebUI Manager
# =============================================================================
#
# A clean, reliable and user-friendly management script for Open-WebUI.
#
# This script launches Open-WebUI in a detached screen session, performs
# a proper health check (port + actual web content), and automatically
# opens the browser when the UI is fully ready.
#
# Features:
# • CUDA Restart option ( CUDA Stack fails sometime after wakeup from suspend)
# • Open-Webui update funktion available
# • Runs Open-WebUI inside a named screen session
# • Automatic free port detection
# • Robust readiness check (HTTP + HTML content)
# • Clean progress indication
# • Stop / Restart / Quit options
# • On timeout: attaches to screen session for debugging
#
# Author: speefak
# Version: 0.5
# Date: May 2026
# =============================================================================
# === Global Configuration ===
DCRoot="$HOME/.open-webui"
ScreenSessionName="open-webui_server"
WUIPort=3000
Browser="firefox_opt"
MAX_WAIT=20
# ===================== OPTIONS =====================
show_help() {
cat <<EOF
Open-WebUI Manager
Usage:
$(basename "$0") [OPTION]
Options:
-u Update Open-WebUI
-r Restart CUDA modules
-h Show this help
No option:
Start Open-WebUI normally
EOF
}
update_open_webui() {
cd "$DCRoot" || {
echo "❌ Directory $DCRoot not found!"
exit 1
}
echo "🔄 Updating Open-WebUI..."
source "$DCRoot/venv/bin/activate"
pip install --upgrade pip
pip install --upgrade open-webui
deactivate
echo "✅ Update complete."
}
CUDA_restart() {
echo "🔁 Restarting NVIDIA/CUDA stack..."
sudo rmmod nvidia_uvm nvidia_drm nvidia_modeset nvidia 2>/dev/null
sudo modprobe nvidia
sudo modprobe nvidia_uvm
sudo modprobe nvidia_drm
sudo modprobe nvidia_modeset
sudo systemctl restart nvidia-persistenced
echo "✅ CUDA stack restarted."
}
handle_options() {
while getopts ":urh" opt; do
case "$opt" in
u)
update_open_webui
exit 0
;;
r)
CUDA_restart
exit 0
;;
h)
show_help
exit 0
;;
\?)
echo "❌ Unknown option: -$OPTARG"
show_help
exit 1
;;
esac
done
}
# ===================== HELPERS =====================
check_for_running_open_webui_server() {
screen -ls | grep -q "$ScreenSessionName"
}
is_port_listening() {
ss -tuln | grep -q ":$1 "
}
http_healthcheck() {
curl -s --max-time 3 "http://localhost:$1" | grep -qi "open-webui\|html\|webui"
}
wait_for_server_ready() {
local port=$1
local waited=0
echo -n "⏳ Waiting for Open-WebUI"
while [ $waited -lt $MAX_WAIT ]; do
if is_port_listening "$port" && http_healthcheck "$port"; then
echo -e "\r✅ Open-WebUI is ready! "
return 0
fi
sleep 2
((waited+=2))
echo -n "."
done
echo -e "\r⚠️ Timeout reached."
if screen -ls | grep -q "$ScreenSessionName"; then
echo "🔗 Attaching to session..."
screen -r "$ScreenSessionName"
else
echo "❌ Server failed to start."
fi
exit 1
}
find_free_port() {
local port=$WUIPort
while ss -tuln | grep -q ":$port "; do
echo "⚠️ Port $port in use"
((port++))
[ $port -gt 65535 ] && {
echo "❌ No free port found"
exit 1
}
done
WUIPort=$port
}
start_server() {
echo "🚀 Starting Open-WebUI..."
cd "$DCRoot" || {
echo "❌ Directory not found"
exit 1
}
screen -dmS "$ScreenSessionName" bash -c "
source venv/bin/activate
open-webui serve --host 0.0.0.0 --port $WUIPort
"
sleep 2
wait_for_server_ready "$WUIPort"
echo "🌐 Opening browser..."
$Browser "http://localhost:$WUIPort" &>/dev/null &
}
stop_server() {
echo "🛑 Stopping Open-WebUI..."
screen -S "$ScreenSessionName" -X quit 2>/dev/null
sleep 1
echo "✅ Stopped."
}
# ===================== MAIN =====================
handle_options "$@"
echo "=== Open-WebUI Manager ==="
if check_for_running_open_webui_server; then
echo "✅ Already running"
echo
read -n 1 -p "Stop / Restart / Quit? [s/r/q] (default s): " choice
echo
choice=${choice:-s}
case "$choice" in
r|R)
stop_server
sleep 2
find_free_port
start_server
;;
q|Q)
echo "👋 Exit"
exit 0
;;
*)
stop_server
;;
esac
else
echo "ℹ️ Not running"
find_free_port
start_server
fi