#!/usr/bin/env bash # Starts HTTP server on port 7860 immediately, runs conversion in background. # The HTTP server is the main foreground process — container stays alive as # long as it's running regardless of what the conversion does. set -euo pipefail mkdir -p /workspace/output /workspace/scratch LOG_FILE="/workspace/output/conversion.log" # Kick off the conversion pipeline in the background before anything else ( exec >> "$LOG_FILE" 2>&1 echo "" echo "════════════════════════════════════════════════════" echo " DeepSeek-Math-V2 GGUF Converter" echo "════════════════════════════════════════════════════" echo "Date : $(date)" echo "Disk : $(df -h /workspace | tail -1)" echo "Memory : $(free -h | grep Mem)" echo "" # Build llama-quantize if not present if ! command -v llama-quantize &>/dev/null; then echo "Building llama-quantize (~2 min)..." cd /opt/llama.cpp cmake -B build \ -DCMAKE_BUILD_TYPE=Release \ -DLLAMA_NATIVE=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DLLAMA_BUILD_TESTS=OFF \ -DLLAMA_BUILD_EXAMPLES=OFF \ -DLLAMA_BUILD_SERVER=OFF \ 2>&1 | tail -3 cmake --build build --config Release --target llama-quantize -j$(nproc) install -m 755 build/bin/llama-quantize /usr/local/bin/llama-quantize echo "llama-quantize ready" cd /workspace fi bash /workspace/scripts/convert.sh if [[ $? -eq 0 ]]; then echo "" echo "════════════════════════════════════════════════════" echo " ✔ Conversion complete! Container staying alive." echo "════════════════════════════════════════════════════" else echo "" echo "════════════════════════════════════════════════════" echo " ✘ Conversion FAILED. Container staying alive." echo "════════════════════════════════════════════════════" fi ) & # Start the HTTP status server in the FOREGROUND — this is PID 1's main job. # Container lives exactly as long as this process lives. exec python3 /workspace/scripts/status_server.py "$LOG_FILE"