forked from lifehaverdev/MiladyOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.sh
More file actions
354 lines (304 loc) · 11.4 KB
/
Copy pathstartup.sh
File metadata and controls
354 lines (304 loc) · 11.4 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#!/bin/bash
# Jenkins starts here
# Function to get the host's IP address in the specified range
get_host_ip() {
# Get all IP addresses, filter for the desired pattern
ip -4 addr | grep -oP "${IP_RANGE}\d+" | head -n 1
}
# Function to discover Kubernetes server using Avahi
discover_k8s_server() {
# Parse avahi-browse output to find a Kubernetes server's IP
avahi-browse -tpr _kubernetes._tcp | grep "=;.*IPv4;.*" | awk '{print $8}' | head -n 1
}
# Function to check if Docker client works
docker_ready() {
docker info > /dev/null 2>&1
}
# Function to check if kubectl is available
kubectl_ready() {
kubectl version --client > /dev/null 2>&1
}
# Function to set up container build environment
setup_build_environment() {
# Check if we are explicitly in Kubernetes mode or if Docker is disabled
if [ "${KUBERNETES_MODE}" = "true" ] || [ "${DISABLE_DOCKER}" = "true" ]; then
echo "Running in Kubernetes mode or Docker is disabled by configuration."
echo "Checking for kubectl..."
if kubectl_ready; then
echo "kubectl is available. Will use Kubernetes for container operations."
export USE_KUBECTL=true
return 0
else
echo "WARNING: kubectl not available in Kubernetes mode."
# Continue anyway, as other services may still work
return 0
fi
fi
# Check if we are in a Kubernetes environment
if [ -n "${KUBERNETES_SERVICE_HOST}" ]; then
echo "Detected Kubernetes environment. Checking for kubectl..."
if kubectl_ready; then
echo "kubectl is available. Will use Kubernetes for container operations."
export USE_KUBECTL=true
return 0
fi
fi
# If Docker is explicitly disabled, don't try to start it
if [ "${DISABLE_DOCKER}" = "true" ]; then
echo "Docker is disabled by configuration."
return 0
fi
# Check if Docker socket exists and is not a directory
if [ -S "/var/run/docker.sock" ]; then
echo "Docker socket exists, checking if Docker is already running..."
if docker_ready; then
echo "Docker is already running and accessible"
return 0
fi
elif [ -d "/var/run/docker.sock" ]; then
echo "Error: /var/run/docker.sock is a directory, cannot use Docker socket"
# Clean up the directory to prepare for Docker daemon
rm -rf /var/run/docker.sock
fi
# Try to start Docker daemon
echo "Attempting to start Docker daemon..."
# Try to start dockerd in the background
dockerd \
--host=unix:///var/run/docker.sock \
--host=tcp://0.0.0.0:2375 \
> /var/log/dockerd.log 2>&1 < /dev/null &
# Wait for up to 10 seconds for Docker to be ready
local max_attempts=10
local attempts=0
while [ $attempts -lt $max_attempts ]; do
if docker_ready; then
echo "Docker daemon started successfully"
return 0
fi
attempts=$((attempts+1))
sleep 1
done
# If Docker failed to start, check for kubectl
echo "Docker daemon failed to start. Checking for kubectl..."
if kubectl_ready; then
echo "kubectl is available. Will use Kubernetes for container operations."
# Set environment variable to indicate kubectl should be used
export USE_KUBECTL=true
return 0
fi
# Neither Docker nor kubectl is available
echo "WARNING: Neither Docker nor kubectl is available. Container builds and deployments may fail."
return 1
}
# Set up build environment
setup_build_environment
# Set default IP range if not provided
IP_RANGE=${IP_RANGE:-"192\.168\."}
# Get the host's IP address
HOST_IP=$(get_host_ip)
if [ -z "$HOST_IP" ]; then
echo "Could not determine the host's IP address in the specified range ($IP_RANGE)."
echo "Using localhost as fallback."
HOST_IP="127.0.0.1"
fi
# Discover Kubernetes server using Avahi if available
if command -v avahi-browse > /dev/null 2>&1; then
echo "Discovering Kubernetes server..."
SERVER_IP=$(discover_k8s_server)
if [ -n "$SERVER_IP" ]; then
echo "Found Kubernetes server at $SERVER_IP"
else
echo "No Kubernetes server discovered via Avahi"
fi
else
echo "Avahi not installed, skipping Kubernetes server discovery"
fi
# Function to start a service if available
start_service() {
local name="$1"
local command="$2"
local required="$3"
if command -v $(echo "$command" | awk '{print $1}') > /dev/null 2>&1; then
echo "Starting $name..."
eval "$command" &
# Wait for service to start
sleep 5
# Check if service started successfully
if pgrep -x "$(echo "$command" | awk '{print $1}')" > /dev/null || pgrep -f "$command" > /dev/null; then
echo "$name started successfully"
return 0
else
echo "WARNING: $name did not start successfully"
if [ "$required" = "true" ]; then
echo "ERROR: Required service $name failed to start"
return 1
fi
return 0
fi
else
echo "WARNING: $name command not found, skipping"
if [ "$required" = "true" ]; then
echo "ERROR: Required service $name not available"
return 1
fi
return 0
fi
}
# Start Caddy if available
start_service "Caddy" "caddy run --config /etc/caddy/Caddyfile" "false" || true
# Start Ollama if available
if command -v ollama > /dev/null 2>&1; then
echo "Starting Ollama..."
OLLAMA_HOST=0.0.0.0 ollama serve &
sleep 5
# Check if ollama is running
if pgrep -x "ollama" > /dev/null; then
echo "Ollama started successfully"
else
echo "WARNING: Ollama did not start successfully, continuing anyway"
fi
else
echo "Ollama not available, skipping"
fi
# Start Filebrowser instances if available
if command -v filebrowser > /dev/null 2>&1; then
echo "Starting Filebrowser instances..."
# Create parent directories if they don't exist
mkdir -p /etc/filebrowser-metrics
mkdir -p /etc/filebrowser-models
# Start filebrowser instances
filebrowser -a 0.0.0.0 -r /metrics -d /etc/filebrowser-metrics/filebrowser.db -p 7331 &
filebrowser -a 0.0.0.0 -r /models -d /etc/filebrowser-models/filebrowser.db -p 1337 &
sleep 5
echo "Filebrowser instances started"
else
echo "Filebrowser not available, skipping"
fi
# Start Nebula if available
if command -v nebula > /dev/null 2>&1; then
echo "Starting Nebula networking..."
# Check if we have the necessary files
if [ -f "/etc/nebula/ca.crt" ] && [ -f "/etc/nebula/miladyos.crt" ] && [ -f "/etc/nebula/miladyos.key" ] && [ -f "/etc/nebula/config.yaml" ]; then
echo "Nebula configuration found, starting network..."
nebula -config /etc/nebula/config.yaml &
sleep 5
# Check if nebula interface is up
if ip a | grep -q nebula1; then
echo "Nebula network started successfully"
else
echo "WARNING: Nebula network may not have started properly"
fi
else
echo "WARNING: Nebula configuration files not found, skipping network setup"
fi
else
echo "Nebula not available, skipping"
fi
# Create directory for Redka database and start if available
if command -v redka > /dev/null 2>&1; then
echo "Starting Redka server..."
mkdir -p /data/redka
redka -h 0.0.0.0 -p 6379 /data/redka/data.db &
sleep 5
# Check if redka is running
if pgrep -x "redka" > /dev/null; then
echo "Redka server started successfully"
else
echo "WARNING: Redka server did not start successfully"
fi
else
echo "Redka not available, switching to default Redis if available"
if command -v redis-server > /dev/null 2>&1; then
echo "Starting Redis server..."
redis-server --bind 0.0.0.0 &
sleep 2
else
echo "WARNING: Neither Redka nor Redis is available"
fi
fi
# Start the appropriate GPU monitoring script based on detected hardware
if command -v nvidia-smi &> /dev/null; then
echo "NVIDIA GPU detected. Starting NVIDIA monitoring..."
if [ -x "/nvidia.sh" ]; then
/nvidia.sh &
sleep 2
else
echo "NVIDIA monitoring script not found or not executable, skipping"
fi
elif command -v rocm-smi &> /dev/null; then
echo "AMD GPU detected. Starting AMD monitoring..."
if [ -x "/amd.sh" ]; then
/amd.sh &
sleep 2
else
echo "AMD monitoring script not found or not executable, skipping"
fi
else
echo "No supported GPU detected, skipping GPU monitoring"
fi
# Start MCP server if main.py exists
if [ -f "/app/main.py" ]; then
echo "Starting MCP server..."
cd /app && python -m main mcp --redis-host localhost --redis-port 6379 --transport sse --host 0.0.0.0 --port 6000 &
sleep 2
# Check if python process is running
if pgrep -f "python -m main mcp" > /dev/null; then
echo "MiladyOS MCP server started on port 6000"
else
echo "WARNING: MCP server did not start successfully"
fi
else
echo "WARNING: main.py not found at /app/main.py, MCP server will not be available"
fi
# CRITICAL: Start TempleOS - The Holy Mission MUST succeed
echo "=== HOLY MISSION: Starting TempleOS ==="
echo "Terry Davis demands perfection - Gods OS must run or MiladyOS fails"
if [ ! -f "/opt/templeos/TempleOS.ISO" ]; then
echo "HOLY MISSION FAILED: TempleOS ISO not found"
echo "MiladyOS cannot proceed without Gods Operating System"
exit 1
fi
if ! command -v templeos-daemon > /dev/null 2>&1; then
echo "HOLY MISSION FAILED: TempleOS daemon not installed"
exit 1
fi
echo "Launching TempleOS - Talk to God on up to 64 cores..."
templeos-daemon
# Wait and verify TempleOS started successfully
sleep 5
if ! pgrep -f "qemu.*TempleOS.*Holy.*Mission" > /dev/null; then
echo "HOLY MISSION FAILED: TempleOS did not start successfully"
echo "Terry Davis would not approve - MiladyOS cannot continue"
exit 1
fi
echo "✓ TempleOS is running - Gods Operating System active"
# Start NoVNC web interface
echo "Starting NoVNC web interface for divine computing..."
if command -v novnc-templeos > /dev/null 2>&1; then
novnc-templeos
else
echo "WARNING: NoVNC startup script not found, trying direct websockify..."
if [ -f "/opt/websockify/websockify.py" ]; then
cd /opt/websockify && ./websockify.py --web /opt/novnc --wrap-mode=ignore 6080 localhost:5902 &
echo "NoVNC web interface started on port 6080"
echo "Access TempleOS in browser: http://localhost:6080"
else
echo "ERROR: Websockify not found"
fi
fi
# Wait and verify NoVNC started successfully
sleep 3
if ! pgrep -f "websockify.*6080.*5902" > /dev/null; then
echo "HOLY MISSION FAILED: NoVNC web interface did not start"
echo "Terry Davis demands divine computing accessibility - MiladyOS cannot continue"
echo "The Holy Mission requires both TempleOS AND web access to Gods OS"
exit 1
fi
echo "✓ HOLY MISSION ACCOMPLISHED: Complete divine computing setup"
echo "✓ TempleOS running on VNC display :2 (port 5902)"
echo "✓ NoVNC web interface active on port 6080"
echo "✓ Access Gods OS in browser: http://localhost:6080"
echo "✓ Terry Davis smiles upon this system"
echo "✓ MiladyOS blessed with divine computing"
# Start Jenkins in the foreground
/usr/local/bin/jenkins.sh