Skip to content

Commit 148d72d

Browse files
authored
fix(build): Pull ollama model before configuring service
1 parent 7aaf61c commit 148d72d

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

05-install-ai.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# ==============================================================================
33
# LuminOS Build Script - Phase 5: Local AI Integration
44
# Author: Gabriel, Project Leader @ LuminOS
5-
# Version: 0.1.6
5+
# Version: 0.1.7
66
# ==============================================================================
77
set -e
88
LUMINOS_CHROOT_DIR="chroot"
@@ -23,13 +23,27 @@ chmod +x ollama
2323
echo "--> Installing Ollama binary into the system..."
2424
mv ollama "$LUMINOS_CHROOT_DIR/usr/local/bin/"
2525

26+
# --- Pull the model BEFORE configuring the service ---
27+
# We need mounts for network access during the pull
28+
echo "--> Mounting virtual filesystems for model download..."
29+
mount --bind /dev "$LUMINOS_CHROOT_DIR/dev"; mount --bind /dev/pts "$LUMINOS_CHROOT_DIR/dev/pts"; mount -t proc /proc "$LUMINOS_CHROOT_DIR/proc"; mount -t sysfs /sys "$LUMINOS_CHROOT_DIR/sys"
30+
31+
echo "--> IMPORTANT: Pulling base model '${BASE_MODEL}'. This will take some time..."
32+
# Run pull directly using the binary, no service needed yet
33+
chroot "$LUMINOS_CHROOT_DIR" env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/local/bin/ollama pull ${BASE_MODEL}
34+
35+
echo "--> Unmounting virtual filesystems after model download..."
36+
umount "$LUMINOS_CHROOT_DIR/sys"; umount "$LUMINOS_CHROOT_DIR/proc"; umount "$LUMINOS_CHROOT_DIR/dev/pts"; umount "$LUMINOS_CHROOT_DIR/dev"
37+
38+
39+
# --- Configure the Service and Lumin Model ---
2640
# Create the script to be run inside the chroot
2741
cat > "$LUMINOS_CHROOT_DIR/tmp/configure_ai.sh" << EOF
2842
#!/bin/bash
2943
set -e
3044
echo "--> Creating dedicated 'ollama' user..."
3145
useradd -r -s /bin/false -m -d /usr/share/ollama ollama
32-
echo "--> Creating Ollama systemd service..."
46+
echo "--> Creating Ollama systemd service file..."
3347
cat > /etc/systemd/system/ollama.service << "SYSTEMD_SERVICE"
3448
[Unit]
3549
Description=Ollama API Server
@@ -44,13 +58,9 @@ RestartSec=3
4458
WantedBy=default.target
4559
SYSTEMD_SERVICE
4660
echo "--> Enabling Ollama service to start on boot..."
61+
# Enable only, don't try to start it here
4762
systemctl enable ollama.service
4863
49-
echo "--> Starting Ollama service now..." # Added step
50-
systemctl start ollama.service # Added command
51-
echo "--> Waiting for Ollama service to initialize..." # Added step
52-
sleep 5 # Added short delay
53-
5464
echo "--> Creating Lumin AI definition directory..."
5565
mkdir -p /usr/local/share/lumin/ai
5666
echo "--> Creating the read-only Modelfile for Lumin..."
@@ -61,26 +71,24 @@ MODELFILE
6171
echo "--> Setting protective ownership and permissions on Modelfile..."
6272
chown root:root /usr/local/share/lumin/ai/Modelfile
6373
chmod 444 /usr/local/share/lumin/ai/Modelfile
74+
75+
echo "--> Creating custom 'Lumin' model from Modelfile..."
76+
# Create the model using the binary, service doesn't need to be running
77+
/usr/local/bin/ollama create lumin -f /usr/local/share/lumin/ai/Modelfile
78+
6479
rm /tmp/configure_ai.sh
6580
EOF
6681

6782
chmod +x "$LUMINOS_CHROOT_DIR/tmp/configure_ai.sh"
6883

69-
# --- Mounts, Chroot Execution, Unmounts ---
70-
echo "--> Mounting virtual filesystems for chroot..."
84+
# --- Mounts, Chroot Execution, Unmounts for Configuration ---
85+
echo "--> Mounting virtual filesystems for chroot configuration..."
7186
mount --bind /dev "$LUMINOS_CHROOT_DIR/dev"; mount --bind /dev/pts "$LUMINOS_CHROOT_DIR/dev/pts"; mount -t proc /proc "$LUMINOS_CHROOT_DIR/proc"; mount -t sysfs /sys "$LUMINOS_CHROOT_DIR/sys"
7287

73-
echo "--> Entering chroot to configure AI service..."
88+
echo "--> Entering chroot to configure AI service and create model..."
7489
chroot "$LUMINOS_CHROOT_DIR" env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /tmp/configure_ai.sh
7590

76-
echo "--> IMPORTANT: Pulling base model '${BASE_MODEL}' inside chroot. This will take some time..."
77-
# Note: Pulling happens *after* the service is started by configure_ai.sh
78-
chroot "$LUMINOS_CHROOT_DIR" env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/local/bin/ollama pull ${BASE_MODEL}
79-
80-
echo "--> Creating custom 'Lumin' model from Modelfile..."
81-
chroot "$LUMINOS_CHROOT_DIR" env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /usr/local/bin/ollama create lumin -f /usr/local/share/lumin/ai/Modelfile
82-
83-
echo "--> Unmounting virtual filesystems..."
91+
echo "--> Unmounting virtual filesystems after configuration..."
8492
umount "$LUMINOS_CHROOT_DIR/sys"; umount "$LUMINOS_CHROOT_DIR/proc"; umount "$LUMINOS_CHROOT_DIR/dev/pts"; umount "$LUMINOS_CHROOT_DIR/dev"
8593

8694
echo ""

0 commit comments

Comments
 (0)