chatbot / start.sh
SuhasGholkar's picture
Create start.sh
084d6a6 verified
#!/usr/bin/env bash
set -euo pipefail
echo "== Runtime environment =="
echo "Python: $(python --version)"
echo "Pip: $(python -m pip --version || true)"
echo "User: $(id)"
echo "Workdir: $(pwd)"
echo "Listing /app:"
ls -la /app || true
echo "PORT is: ${PORT:-7860}"
# Convert any CRLF to LF for safety (no-op if dos2unix not present)
if command -v dos2unix >/dev/null 2>&1; then
find /app -type f -maxdepth 1 -name "*.py" -print -exec dos2unix {} \; || true
fi
# Sanity test: can we bind to the port?
python - <<'PY'
import os, socket, sys
port = int(os.environ.get("PORT", "7860"))
s = socket.socket()
try:
s.bind(("0.0.0.0", port))
s.close()
print(f"Bind check passed on port {port}.")
except OSError as e:
print(f"Bind check failed on port {port}: {e}", file=sys.stderr)
sys.exit(1)
PY
# Show installed packages (short)
python - <<'PY'
import pkgutil
mods = sorted(m.name for m in pkgutil.iter_modules())
print("Some installed modules:", ", ".join(mods[:30]), "...")
PY
echo "== Launching Streamlit =="
exec streamlit run app.py --server.port="${PORT:-7860}" --server.address=0.0.0.0 --server.enableCORS=false --server.enableXsrfProtection=false --logger.level=debug