Files

1 line
53 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "blackeagle686/baraka", "files": {".env": {"c63e1c146d3a6572d9b143769624efa3b5e8a4cc": {"t": 1785604645.1138558, "n": 704, "h": "2c41e8e797118687", "c": "# ==========================================\n# Baraka SaaS Platform Secure Environment Keys Template\n# ==========================================\n\n# Django Settings\nSECRET_KEY=django-insecure-ru)8&79*#fw%rlh1(0d4a13gi)l11_*-!^6_$2du5do&!ryw*&\nDEBUG=False\nALLOWED_HOSTS=*,127.0.0.1,localhost\n\n# CORS Policy configuration (comma-separated origins)\nCORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080\n\n# Database Settings\nDB_HOST=127.0.0.1\nDB_NAME=baraka_db\nDB_USER=tlk@tlk\nDB_PASSWORD=tlk_vesta_1680\nDB_PORT=5432\n\n# Redis & Celery (Leave empty to use local fallbacks)\nREDIS_URL=redis://127.0.0.1:6379/2\nCELERY_BROKER_URL=redis://127.0.0.1:6379/2\nCELERY_RESULT_BACKEND=redis://127.0.0.1:6379/2\n"}}, ".env.example": {"a059a097172e88f1bb45b5c62a7ef41a29b069ea": {"t": 1785604648.4408526, "n": 714, "h": "b89fea94eaba6b67", "c": "# ==========================================\n# Baraka SaaS Platform Secure Environment Keys Template\n# ==========================================\n\n# Django Settings\nSECRET_KEY=django-insecure-ru)8&79*#fw%rlh1(0d4a13gi)l11_*-!^6_$2du5do&!ryw*&\nDEBUG=False\nALLOWED_HOSTS=127.0.0.1,localhost,.vercel.app\n\n# CORS Policy configuration (comma-separated origins)\nCORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080\n\n# Database Settings\nDB_HOST=127.0.0.1\nDB_NAME=baraka_db\nDB_USER=tlk@tlk\nDB_PASSWORD=tlk_vesta_1680\nDB_PORT=5432\n\n# Redis & Celery (Leave empty to use local fallbacks)\nREDIS_URL=redis://127.0.0.1:6379/2\nCELERY_BROKER_URL=redis://127.0.0.1:6379/2\nCELERY_RESULT_BACKEND=redis://127.0.0.1:6379/2\n"}}, "deploy_baraka.py": {"33288fde5bea6a4fc857bda7ae87670ed91961c3": {"t": 1785604650.1366537, "n": 15104, "h": "078594578e6b8695", "c": "#!/usr/bin/env python3\nimport subprocess\nimport sys\nimport time\nimport os\nimport signal\nimport json\nimport urllib.request\nfrom pathlib import Path\n\nSCRIPT_DIR = Path(__file__).resolve().parent\nLOG_DIR = SCRIPT_DIR / \"logs\"\nPID_DIR = SCRIPT_DIR / \".pids\"\nVENV_DIR = SCRIPT_DIR / \"venv\"\nGUNICORN = VENV_DIR / \"bin\" / \"gunicorn\"\nCELERY = VENV_DIR / \"bin\" / \"celery\"\nPYTHON = VENV_DIR / \"bin\" / \"python\"\nMANAGE = SCRIPT_DIR / \"manage.py\"\n\nDJANGO_LOG = LOG_DIR / \"django.log\"\nCELERY_LOG = LOG_DIR / \"celery.log\"\nNGROK_LOG = LOG_DIR / \"ngrok.log\"\nNGINX_ACCESS = Path(\"/var/log/nginx/access.log\")\nNGINX_ERROR = Path(\"/var/log/nginx/error.log\")\n\nDJANGO_PID = PID_DIR / \"django.pid\"\nCELERY_PID = PID_DIR / \"celery.pid\"\nNGROK_PID = PID_DIR / \"ngrok.pid\"\n\nprocesses = []\n\ndef ensure_dirs():\n LOG_DIR.mkdir(parents=True, exist_ok=True)\n PID_DIR.mkdir(parents=True, exist_ok=True)\n\ndef read_pid(path):\n try:\n return int(path.read_text().strip())\n except (FileNotFoundError, ValueError):\n return None\n\ndef is_running(pid):\n if pid is None:\n return False\n try:\n os.kill(pid, 0)\n return True\n except OSError:\n return False\n\ndef pid_status(path):\n pid = read_pid(path)\n if pid is None:\n return \"stopped\", None\n if is_running(pid):\n return \"running\", pid\n return \"crashed\", pid\n\ndef write_pid(path, pid):\n path.write_text(str(pid))\n\ndef remove_pid(path):\n path.unlink(missing_ok=True)\n\ndef print_header(title):\n print()\n print(f\"\\033[0;36m{'='*73}\\033[0m\")\n print(f\"\\033[1m Baraka Production Service — {title}\\033[0m\")\n print(f\"\\033[0;36m{'='*73}\\033[0m\")\n print()\n\ndef step(msg):\n print(f\"\\033[0;32m{msg}\\033[0m\")\n\ndef warn(msg):\n print(f\"\\033[1;33m {msg}\\033[0m\")\n\ndef error(msg):\n print(f\"\\033[0;31m{msg}\\033[0m\")\n\n# --- Service Start -----------------------------------------------------------\n\ndef start_django():\n ensure_dirs()\n status, pid = pid_status(DJANGO_PID)\n if status == \"running\":\n warn(f\"Django/Gunicorn is already running (PID {pid})\")\n return\n if not GUNICORN.exists():\n error(\"Virtual environment not found! Run 'deploy_baraka.sh deploy' first.\")\n return\n step(\"Starting Django/Gunicorn server in background...\")\n cmd = [\n str(GUNICORN), \"backend.wsgi:application\",\n \"--bind\", \"127.0.0.1:8003\",\n \"--workers\", \"4\",\n \"--threads\", \"2\",\n \"--timeout\", \"120\",\n \"--access-logfile\", str(DJANGO_LOG),\n \"--error-logfile\", str(DJANGO_LOG),\n ]\n with open(DJANGO_LOG, \"a\") as log:\n p = subprocess.Popen(cmd, stdout=log, stderr=log, cwd=str(SCRIPT_DIR))\n write_pid(DJANGO_PID, p.pid)\n time.sleep(1)\n if is_running(p.pid):\n print(f\" \\033[0;32m●\\033[0m Django/Gunicorn started (PID {p.pid})\")\n else:\n error(\"Django/Gunicorn failed to start! Last log lines:\")\n lines = DJANGO_LOG.read_text().splitlines()[-10:] if DJANGO_LOG.exists() else []\n for line in lines:\n print(f\" {line}\")\n remove_pid(DJANGO_PID)\n\ndef start_celery():\n ensure_dirs()\n status, pid = pid_status(CELERY_PID)\n if status == \"running\":\n warn(f\"Celery is already running (PID {pid})\")\n return\n if not CELERY.exists():\n error(\"Virtual environment not found! Run 'deploy_baraka.sh deploy' first.\")\n return\n step(\"Starting Celery worker in background...\")\n cmd = [\n str(CELERY), \"-A\", \"backend\", \"worker\",\n \"--loglevel=info\",\n \"--logfile\", str(CELERY_LOG),\n ]\n with open(CELERY_LOG, \"a\") as log:\n p = subprocess.Popen(cmd, stdout=log, stderr=log, cwd=str(SCRIPT_DIR))\n write_pid(CELERY_PID, p.pid)\n time.sleep(1)\n if is_running(p.pid):\n print(f\" \\033[0;32m●\\033[0m Celery worker started (PID {p.pid})\")\n else:\n error(\"Celery failed to start! Last log lines:\")\n lines = CELERY_LOG.read_text().splitlines()[-10:] if CELERY_LOG.exists() else []\n for line in lines:\n print(f\" {line}\")\n remove_pid(CELERY_PID)\n\ndef start_ngrok():\n ensure_dirs()\n if not shutil_which(\"ngrok\"):\n warn(\"Ngrok is not installed — skipping.\")\n return\n status, pid = pid_status(NGROK_PID)\n if status == \"running\":\n warn(f\"Ngrok is already running (PID {pid})\")\n return\n step(\"Starting Ngrok tunnel in background...\")\n cmd = [\"ngrok\", \"http\", \"80\", \"--log=stdout\"]\n with open(NGROK_LOG, \"a\") as log:\n p = subprocess.Popen(cmd, stdout=log, stderr=log)\n write_pid(NGROK_PID, p.pid)\n print(f\" \\033[0;32m●\\033[0m Ngrok tunnel started (PID {p.pid})\")\n time.sleep(4)\n api_port = _find_ngrok_api_port()\n if api_port:\n url = _get_ngrok_url(api_port)\n if url:\n print(f\" \\033[0;32m\\U0001f310\\033[0m Ngrok URL: \\033[1m{url}\\033[0m\")\n else:\n print(f\" \\033[1;33m\\u23f3\\033[0m Ngrok URL pending — check: curl -s http://127.0.0.1:{api_port}/api/tunnels\")\n else:\n print(f\" \\033[1;33m\\u23f3\\033[0m Ngrok API not ready — check logs: ./deploy_baraka.sh logs ngrok\")\n\ndef start_nginx():\n if not shutil_which(\"nginx\"):\n warn(\"Nginx is not installed — skipping.\")\n return\n step(\"Starting Nginx...\")\n try:\n subprocess.run([\"sudo\", \"systemctl\", \"start\", \"nginx\"], check=False)\n print(\" \\033[0;32m●\\033[0m Nginx started\")\n except Exception:\n warn(\"Nginx failed to start via systemctl. Trying nginx directly...\")\n try:\n subprocess.run([\"sudo\", \"nginx\"], check=True)\n print(\" \\033[0;32m●\\033[0m Nginx started (direct)\")\n except Exception:\n error(\"Could not start Nginx. Check: sudo nginx -t\")\n\ndef start_all():\n print_header(\"Starting All Services\")\n start_nginx()\n start_django()\n start_celery()\n start_ngrok()\n print()\n print(\"\\033[0;32mAll services started in background.\\033[0m\")\n print(\" Use ./deploy_baraka.py logs <service> to view logs.\")\n print(\" Use ./deploy_baraka.py status to check service status.\")\n print()\n\n# --- Service Stop ------------------------------------------------------------\n\ndef kill_pid(path, name):\n pid = read_pid(path)\n if pid is None:\n print(f\" \\033[1;33m\\u25a0\\033[0m {name} is not running (no PID file)\")\n return\n if is_running(pid):\n try:\n os.kill(pid, signal.SIGTERM)\n for _ in range(10):\n time.sleep(0.5)\n if not is_running(pid):\n break\n if is_running(pid):\n os.kill(pid, signal.SIGKILL)\n print(f\" \\033[0;31m\\u25a0\\033[0m {name} stopped (PID {pid})\")\n except ProcessLookupError:\n print(f\" \\033[1;33m\\u25a0\\033[0m {name} was not running (stale PID {pid})\")\n else:\n print(f\" \\033[1;33m\\u25a0\\033[0m {name} was not running (stale PID {pid})\")\n remove_pid(path)\n\ndef stop_django():\n kill_pid(DJANGO_PID, \"Django/Gunicorn\")\n\ndef stop_celery():\n kill_pid(CELERY_PID, \"Celery\")\n\ndef stop_ngrok():\n kill_pid(NGROK_PID, \"Ngrok\")\n\ndef stop_nginx():\n if not shutil_which(\"nginx\"):\n return\n print(\" \\033[0;31m\\u25a0\\033[0m Stopping Nginx...\")\n subprocess.run([\"sudo\", \"systemctl\", \"stop\", \"nginx\"], stderr=subprocess.DEVNULL, check=False)\n print(\" \\033[0;31m\\u25a0\\033[0m Nginx stopped\")\n\ndef stop_all():\n print_header(\"Stopping All Services\")\n stop_ngrok()\n stop_celery()\n stop_django()\n stop_nginx()\n print()\n print(\"\\033[0;31mAll services stopped.\\033[0m\")\n print()\n\n# --- Service Status ----------------------------------------------------------\n\ndef _find_ngrok_api_port():\n for port in range(4040, 4045):\n try:\n with urllib.request.urlopen(f\"http://127.0.0.1:{port}/api/tunnels\", timeout=1):\n return port\n except Exception:\n continue\n return None\n\ndef _get_ngrok_url(port):\n try:\n with urllib.request.urlopen(f\"http://127.0.0.1:{port}/api/tunnels\", timeout=2) as r:\n data = json.loads(r.read().decode())\n return data[\"tunnels\"][0][\"public_url\"]\n except Exception:\n return None\n\ndef check_status():\n print_header(\"Service Status\")\n\n # Nginx\n if not shutil_which(\"nginx\"):\n print(f\" \\033[1;33m\\u25cf\\033[0m Nginx — \\033[1;33mNot Installed\\033[0m\")\n elif subprocess.run([\"systemctl\", \"is-active\", \"--quiet\", \"nginx\"], stderr=subprocess.DEVNULL).returncode == 0:\n print(f\" \\033[0;32m\\u25cf\\033[0m Nginx — \\033[0;32mRunning\\033[0m\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m Nginx — \\033[0;31mStopped\\033[0m\")\n\n # Django\n st, pid = pid_status(DJANGO_PID)\n if st == \"running\":\n print(f\" \\033[0;32m\\u25cf\\033[0m Django/Gunicorn — \\033[0;32mRunning\\033[0m (PID {pid})\")\n elif st == \"crashed\":\n print(f\" \\033[1;33m\\u25cf\\033[0m Django/Gunicorn — \\033[1;33mCrashed\\033[0m (stale PID) — check: ./deploy_baraka.py logs django\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m Django/Gunicorn — \\033[0;31mStopped\\033[0m\")\n\n # Celery\n st, pid = pid_status(CELERY_PID)\n if st == \"running\":\n print(f\" \\033[0;32m\\u25cf\\033[0m Celery — \\033[0;32mRunning\\033[0m (PID {pid})\")\n elif st == \"crashed\":\n print(f\" \\033[1;33m\\u25cf\\033[0m Celery — \\033[1;33mCrashed\\033[0m (stale PID) — check: ./deploy_baraka.py logs celery\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m Celery — \\033[0;31mStopped\\033[0m\")\n\n # Ngrok\n st, pid = pid_status(NGROK_PID)\n if st == \"running\":\n api_port = _find_ngrok_api_port()\n url = _get_ngrok_url(api_port) if api_port else \"N/A\"\n print(f\" \\033[0;32m\\u25cf\\033[0m Ngrok — \\033[0;32mRunning\\033[0m (PID {pid}) → \\033[1m{url}\\033[0m\")\n elif st == \"crashed\":\n print(f\" \\033[1;33m\\u25cf\\033[0m Ngrok — \\033[1;33mCrashed\\033[0m (stale PID) — check: ./deploy_baraka.py logs ngrok\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m Ngrok — \\033[0;31mStopped\\033[0m\")\n\n # Redis\n r = subprocess.run([\"systemctl\", \"is-active\", \"--quiet\", \"redis-server\"], stderr=subprocess.DEVNULL).returncode\n if r == 0 or shutil_which(\"redis-server\"):\n print(f\" \\033[0;32m\\u25cf\\033[0m Redis — \\033[0;32mRunning\\033[0m\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m Redis — \\033[0;31mStopped\\033[0m\")\n\n # PostgreSQL\n r = subprocess.run([\"systemctl\", \"is-active\", \"--quiet\", \"postgresql\"], stderr=subprocess.DEVNULL).returncode\n if r == 0:\n print(f\" \\033[0;32m\\u25cf\\033[0m PostgreSQL — \\033[0;32mRunning\\033[0m\")\n else:\n print(f\" \\033[0;31m\\u25cf\\033[0m PostgreSQL — \\033[0;31mStopped\\033[0m\")\n\n print()\n\n# --- Logs --------------------------------------------------------------------\n\ndef show_logs(service, lines=50):\n log_files = {\n \"django\": DJANGO_LOG,\n \"gunicorn\": DJANGO_LOG,\n \"backend\": DJANGO_LOG,\n \"celery\": CELERY_LOG,\n \"worker\": CELERY_LOG,\n \"ngrok\": NGROK_LOG,\n \"tunnel\": NGROK_LOG,\n \"frontend\": None,\n \"nginx\": None,\n \"web\": None,\n }\n\n if service == \"all\":\n print_header(\"All Service Logs (combined)\")\n files = [f for f in [DJANGO_LOG, CELERY_LOG, NGROK_LOG] if f.exists()]\n try:\n subprocess.run([\"tail\", \"-f\", \"-n\", str(lines)] + files, check=False)\n except KeyboardInterrupt:\n pass\n return\n\n if service in (\"frontend\", \"nginx\", \"web\"):\n print_header(\"Nginx/Frontend Logs\")\n files = [f for f in [NGINX_ACCESS, NGINX_ERROR] if f.exists()]\n if not files:\n error(\"No Nginx logs found. Is Nginx running?\")\n return\n try:\n subprocess.run([\"sudo\", \"tail\", \"-f\", \"-n\", str(lines)] + files, check=False)\n except KeyboardInterrupt:\n pass\n return\n\n log = log_files.get(service)\n if log is None:\n error(f\"Unknown service: '{service}'\")\n print()\n print(\" Available services: django, celery, frontend, ngrok, all\")\n print(\" Usage: ./deploy_baraka.py logs <service>\")\n return\n\n if log.exists():\n print_header(f\"{service.capitalize()} Logs\")\n try:\n subprocess.run([\"tail\", \"-f\", \"-n\", str(lines), str(log)], check=False)\n except KeyboardInterrupt:\n pass\n else:\n error(f\"No {service.capitalize()} logs found. Is the service running?\")\n print(f\" Expected log file: {log}\")\n\n# --- Shell Command Delegation ------------------------------------------------\n\ndef run_shell(command):\n script = SCRIPT_DIR / \"deploy_baraka.sh\"\n if not script.exists():\n error(\"deploy_baraka.sh not found!\")\n return\n os.execv(\"/bin/bash\", [\"bash\", str(script), command])\n\n# --- Main Entry Point --------------------------------------------------------\n\ndef main():\n if len(sys.argv) < 2 or sys.argv[1] in (\"help\", \"-h\", \"--help\"):\n print()\n print(\"\\033[1mBaraka Deployment Script (Python)\\033[0m\")\n print()\n print(\"Usage: ./deploy_baraka.py [command]\")\n print()\n print(\"Commands:\")\n print(\" \\033[0;36mdeploy\\033[0m Full deployment (install deps + configure + start)\")\n print(\" \\033[0;36mbaraka\\033[0m First-time Postgres setup (user, db, migrations)\")\n print(\" \\033[0;36mstart\\033[0m Start all background services\")\n print(\" \\033[0;36mstop\\033[0m Stop all background services\")\n print(\" \\033[0;36mrestart\\033[0m Restart all background services\")\n print(\" \\033[0;36mstatus\\033[0m Show status of all services\")\n print(\" \\033[0;36mlogs <service>\\033[0m Tail logs for a service\")\n print(\" \\033[0;36mhelp\\033[0m Show this help message\")\n print()\n return\n\n command = sys.argv[1]\n service = sys.argv[2] if len(sys.argv) > 2 else None\n\n if command in (\"deploy\", \"install\", \"setup\", \"baraka\"):\n run_shell(command)\n\n elif command == \"start\":\n start_all()\n\n elif command == \"stop\":\n stop_all()\n\n elif command == \"restart\":\n stop_all()\n start_all()\n\n elif command == \"status\":\n check_status()\n\n elif command in (\"logs\", \"log\"):\n if not service:\n error(\"Please specify a service to view logs for.\")\n print()\n print(\" Usage: ./deploy_baraka.py logs <service>\")\n print()\n print(\" Available services: django, celery, frontend, ngrok, all\")\n sys.exit(1)\n show_logs(service)\n\n else:\n error(f\"Unknown command: '{command}'\")\n print(f\" Run \\033[0;36m./deploy_baraka.py help\\033[0m to see available commands.\")\n sys.exit(1)\n\n\ndef shutil_which(cmd):\n return subprocess.run([\"which\", cmd], capture_output=True).returncode == 0\n\n\nif __name__ == \"__main__\":\n main()\n"}}, "deploy_baraka.sh": {"cbf9d6469c71f65b1eb9a03a73bd5c070c04e60f": {"t": 1785604652.0244482, "n": 24541, "h": "84a822d045b852ff", "c": "#!/bin/bash\n# ==============================================================================\n# 🚀 Baraka Delivery SaaS Platform — Production Server Deployment Script\n# Target OS: Ubuntu 20.04 LTS / 22.04 LTS / 24.04 LTS\n#\n# Usage:\n# ./deploy_baraka.sh — Full deployment (install + start all)\n# ./deploy_baraka.sh start — Start all background services\n# ./deploy_baraka.sh stop — Stop all background services\n# ./deploy_baraka.sh restart — Restart all background services\n# ./deploy_baraka.sh status — Show status of all services\n# ./deploy_baraka.sh logs django — Tail Django/Gunicorn logs\n# ./deploy_baraka.sh logs celery — Tail Celery worker logs\n# ./deploy_baraka.sh logs frontend — Tail Nginx/frontend logs\n# ./deploy_baraka.sh logs ngrok — Tail Ngrok tunnel logs\n# ./deploy_baraka.sh logs all — Tail all logs combined\n# ==============================================================================\n\n# --- Configuration -----------------------------------------------------------\nSCRIPT_DIR=\"$(cd \"$(dirname \"${BASH_SOURCE[0]}\")\" && pwd)\"\nLOG_DIR=\"$SCRIPT_DIR/logs\"\nPID_DIR=\"$SCRIPT_DIR/.pids\"\n\nDJANGO_LOG=\"$LOG_DIR/django.log\"\nCELERY_LOG=\"$LOG_DIR/celery.log\"\nNGROK_LOG=\"$LOG_DIR/ngrok.log\"\nNGINX_ACCESS_LOG=\"/var/log/nginx/access.log\"\nNGINX_ERROR_LOG=\"/var/log/nginx/error.log\"\n\nDJANGO_PID=\"$PID_DIR/django.pid\"\nCELERY_PID=\"$PID_DIR/celery.pid\"\nNGROK_PID=\"$PID_DIR/ngrok.pid\"\n\n# Colors for terminal output\nRED='\\033[0;31m'\nGREEN='\\033[0;32m'\nYELLOW='\\033[1;33m'\nCYAN='\\033[0;36m'\nBOLD='\\033[1m'\nNC='\\033[0m' # No Color\n\n# --- Helper Functions --------------------------------------------------------\n\nensure_dirs() {\n mkdir -p \"$LOG_DIR\" \"$PID_DIR\"\n}\n\nprint_header() {\n echo \"\"\n echo -e \"${CYAN}=========================================================================${NC}\"\n echo -e \"${BOLD} 🔥 Baraka Production Service — $1${NC}\"\n echo -e \"${CYAN}=========================================================================${NC}\"\n echo \"\"\n}\n\nprint_step() {\n echo -e \"${GREEN}$1${NC}\"\n}\n\nprint_warn() {\n echo -e \"${YELLOW}⚠️ $1${NC}\"\n}\n\nprint_error() {\n echo -e \"${RED}❌ $1${NC}\"\n}\n\nis_running() {\n local pidfile=\"$1\"\n if [ -f \"$pidfile\" ]; then\n local pid\n pid=$(cat \"$pidfile\")\n if kill -0 \"$pid\" 2>/dev/null; then\n return 0\n fi\n fi\n return 1\n}\n\nkill_pid() {\n local pidfile=\"$1\"\n local name=\"$2\"\n if [ -f \"$pidfile\" ]; then\n local pid\n pid=$(cat \"$pidfile\")\n if kill -0 \"$pid\" 2>/dev/null; then\n kill \"$pid\" 2>/dev/null\n # Wait up to 5 seconds for graceful shutdown\n for i in $(seq 1 10); do\n if ! kill -0 \"$pid\" 2>/dev/null; then\n break\n fi\n sleep 0.5\n done\n # Force kill if still alive\n if kill -0 \"$pid\" 2>/dev/null; then\n kill -9 \"$pid\" 2>/dev/null\n fi\n echo -e \" ${RED}■${NC} $name stopped (PID $pid)\"\n else\n echo -e \" ${YELLOW}■${NC} $name was not running (stale PID $pid)\"\n fi\n rm -f \"$pidfile\"\n else\n echo -e \" ${YELLOW}■${NC} $name is not running (no PID file)\"\n fi\n}\n\n# --- Service Start -----------------------------------------------------------\n\nstart_django() {\n ensure_dirs\n if [ ! -f \"$SCRIPT_DIR/venv/bin/gunicorn\" ]; then\n print_error \"Virtual environment not found! Run './deploy_baraka.sh deploy' first.\"\n return 1\n fi\n if is_running \"$DJANGO_PID\"; then\n print_warn \"Django/Gunicorn is already running (PID $(cat \"$DJANGO_PID\"))\"\n return\n fi\n print_step \"🚀 Starting Django/Gunicorn server in background...\"\n cd \"$SCRIPT_DIR\"\n nohup ./venv/bin/gunicorn backend.wsgi:application \\\n --bind 127.0.0.1:8003 \\\n --workers 4 \\\n --threads 2 \\\n --timeout 120 \\\n --access-logfile \"$DJANGO_LOG\" \\\n --error-logfile \"$DJANGO_LOG\" \\\n >> \"$DJANGO_LOG\" 2>&1 &\n local DJPID=$!\n echo \"$DJPID\" > \"$DJANGO_PID\"\n sleep 1\n if kill -0 \"$DJPID\" 2>/dev/null; then\n echo -e \" ${GREEN}●${NC} Django/Gunicorn started (PID $DJPID)\"\n else\n print_error \"Django/Gunicorn failed to start! Last log lines:\"\n tail -n 10 \"$DJANGO_LOG\" 2>/dev/null | sed 's/^/ /'\n rm -f \"$DJANGO_PID\"\n fi\n}\n\nstart_celery() {\n ensure_dirs\n if [ ! -f \"$SCRIPT_DIR/venv/bin/celery\" ]; then\n print_error \"Virtual environment not found! Run './deploy_baraka.sh deploy' first.\"\n return 1\n fi\n if is_running \"$CELERY_PID\"; then\n print_warn \"Celery is already running (PID $(cat \"$CELERY_PID\"))\"\n return\n fi\n print_step \"📦 Starting Celery worker in background...\"\n cd \"$SCRIPT_DIR\"\n nohup ./venv/bin/celery -A backend worker \\\n --loglevel=info \\\n --logfile=\"$CELERY_LOG\" \\\n >> \"$CELERY_LOG\" 2>&1 &\n local CLPID=$!\n echo \"$CLPID\" > \"$CELERY_PID\"\n sleep 1\n if kill -0 \"$CLPID\" 2>/dev/null; then\n echo -e \" ${GREEN}●${NC} Celery worker started (PID $CLPID)\"\n else\n print_error \"Celery failed to start! Last log lines:\"\n tail -n 10 \"$CELERY_LOG\" 2>/dev/null | sed 's/^/ /'\n rm -f \"$CELERY_PID\"\n fi\n}\n\nstart_ngrok() {\n ensure_dirs\n if ! command -v ngrok &>/dev/null; then\n print_warn \"Ngrok is not installed — skipping. (Run: sudo apt-get install -y ngrok)\"\n return\n fi\n # Kill any lingering ngrok instances (from other projects or stale PIDs)\n pkill -x ngrok 2>/dev/null || true\n rm -f \"$NGROK_PID\"\n sleep 1\n print_step \"🚇 Starting Ngrok tunnel in background...\"\n # Tunnel to Nginx (port 80) — serves frontend and proxies /api/ to Django\n nohup ngrok http 80 --log=stdout >> \"$NGROK_LOG\" 2>&1 &\n local ngrok_pid=$!\n echo \"$ngrok_pid\" > \"$NGROK_PID\"\n echo -e \" ${GREEN}●${NC} Ngrok tunnel started (PID $ngrok_pid)\"\n\n sleep 4\n # Auto-detect ngrok API port (it varies: 4040, 4041, 4042, ...)\n local api_port\n for port in 4040 4041 4042 4043 4044; do\n if curl -s \"http://127.0.0.1:$port/api/tunnels\" >/dev/null 2>&1; then\n api_port=$port\n break\n fi\n done\n if [ -n \"$api_port\" ]; then\n local ngrok_url\n ngrok_url=$(python3 -c \"import urllib.request, json; print(json.loads(urllib.request.urlopen('http://127.0.0.1:${api_port}/api/tunnels').read().decode())['tunnels'][0]['public_url'])\" 2>/dev/null || echo \"\")\n if [ -n \"$ngrok_url\" ]; then\n echo -e \" ${GREEN}🌐${NC} Ngrok URL: ${BOLD}$ngrok_url${NC}\"\n else\n echo -e \" ${YELLOW}⏳${NC} Ngrok URL pending — check with: ${CYAN}curl -s http://127.0.0.1:${api_port}/api/tunnels${NC}\"\n fi\n else\n echo -e \" ${YELLOW}⏳${NC} Ngrok API not ready yet — check logs: ./deploy_baraka.sh logs ngrok\"\n fi\n}\n\nstart_nginx() {\n if ! command -v nginx &>/dev/null; then\n print_warn \"Nginx is not installed — skipping. (Run: sudo apt-get install -y nginx)\"\n return\n fi\n print_step \"🌐 Starting Nginx...\"\n if sudo systemctl start nginx 2>/dev/null; then\n echo -e \" ${GREEN}●${NC} Nginx started\"\n else\n print_warn \"Nginx failed to start via systemctl. Trying nginx directly...\"\n if sudo nginx 2>/dev/null; then\n echo -e \" ${GREEN}●${NC} Nginx started (direct)\"\n else\n print_error \"Could not start Nginx. Check: sudo nginx -t\"\n fi\n fi\n}\n\nstart_all() {\n print_header \"Starting All Services\"\n start_nginx\n start_django\n start_celery\n start_ngrok\n echo \"\"\n echo -e \"${GREEN}✅ All services started in background.${NC}\"\n echo -e \" Use ${CYAN}./deploy_baraka.sh logs <service>${NC} to view logs.\"\n echo -e \" Use ${CYAN}./deploy_baraka.sh status${NC} to check service status.\"\n echo \"\"\n}\n\n# --- Service Stop ------------------------------------------------------------\n\nstop_django() {\n kill_pid \"$DJANGO_PID\" \"Django/Gunicorn\"\n}\n\nstop_celery() {\n kill_pid \"$CELERY_PID\" \"Celery\"\n}\n\nstop_ngrok() {\n kill_pid \"$NGROK_PID\" \"Ngrok\"\n # Kill any other lingering ngrok processes\n pkill -x ngrok 2>/dev/null || true\n rm -f \"$NGROK_PID\"\n}\n\nstop_nginx() {\n if ! command -v nginx &>/dev/null; then\n return\n fi\n echo -e \" ${RED}■${NC} Stopping Nginx...\"\n sudo systemctl stop nginx 2>/dev/null || sudo nginx -s stop 2>/dev/null || true\n echo -e \" ${RED}■${NC} Nginx stopped\"\n}\n\nstop_all() {\n print_header \"Stopping All Services\"\n stop_ngrok\n stop_celery\n stop_django\n stop_nginx\n echo \"\"\n echo -e \"${RED}🛑 All services stopped.${NC}\"\n echo \"\"\n}\n\n# --- Service Status ----------------------------------------------------------\n\n# Returns status label: Running, Stopped, or Crashed (pid file exists but process dead)\n_pid_status() {\n local pidfile=\"$1\"\n if [ ! -f \"$pidfile\" ]; then\n echo \"Stopped\"\n elif kill -0 \"$(cat \"$pidfile\")\" 2>/dev/null; then\n echo \"Running\"\n else\n echo \"Crashed\"\n fi\n}\n\ncheck_status() {\n print_header \"Service Status\"\n\n # Nginx\n if ! command -v nginx &>/dev/null; then\n echo -e \" ${YELLOW}●${NC} Nginx — ${YELLOW}Not Installed${NC}\"\n elif systemctl is-active --quiet nginx 2>/dev/null || pgrep -x nginx &>/dev/null; then\n echo -e \" ${GREEN}●${NC} Nginx — ${GREEN}Running${NC}\"\n else\n echo -e \" ${RED}●${NC} Nginx — ${RED}Stopped${NC}\"\n fi\n\n # Django\n local djstatus; djstatus=$(_pid_status \"$DJANGO_PID\")\n case \"$djstatus\" in\n Running) echo -e \" ${GREEN}●${NC} Django/Gunicorn — ${GREEN}Running${NC} (PID $(cat \"$DJANGO_PID\"))\" ;;\n Crashed) echo -e \" ${YELLOW}●${NC} Django/Gunicorn — ${YELLOW}Crashed${NC} (stale PID) — check: ./deploy_baraka.sh logs django\" ;;\n *) echo -e \" ${RED}●${NC} Django/Gunicorn — ${RED}Stopped${NC}\" ;;\n esac\n\n # Celery\n local clstatus; clstatus=$(_pid_status \"$CELERY_PID\")\n case \"$clstatus\" in\n Running) echo -e \" ${GREEN}●${NC} Celery — ${GREEN}Running${NC} (PID $(cat \"$CELERY_PID\"))\" ;;\n Crashed) echo -e \" ${YELLOW}●${NC} Celery — ${YELLOW}Crashed${NC} (stale PID) — check: ./deploy_baraka.sh logs celery\" ;;\n *) echo -e \" ${RED}●${NC} Celery — ${RED}Stopped${NC}\" ;;\n esac\n\n # Ngrok\n local nkstatus; nkstatus=$(_pid_status \"$NGROK_PID\")\n case \"$nkstatus\" in\n Running)\n local ngrok_url ngrok_api_port\n for port in 4040 4041 4042 4043 4044; do\n if curl -s \"http://127.0.0.1:$port/api/tunnels\" >/dev/null 2>&1; then\n ngrok_api_port=$port\n break\n fi\n done\n if [ -n \"$ngrok_api_port\" ]; then\n ngrok_url=$(python3 -c \"import urllib.request, json; print(json.loads(urllib.request.urlopen('http://127.0.0.1:${ngrok_api_port}/api/tunnels').read().decode())['tunnels'][0]['public_url'])\" 2>/dev/null || echo \"N/A\")\n else\n ngrok_url=\"N/A\"\n fi\n echo -e \" ${GREEN}●${NC} Ngrok — ${GREEN}Running${NC} (PID $(cat \"$NGROK_PID\")) → ${BOLD}$ngrok_url${NC}\"\n ;;\n Crashed) echo -e \" ${YELLOW}●${NC} Ngrok — ${YELLOW}Crashed${NC} (stale PID) — check: ./deploy_baraka.sh logs ngrok\" ;;\n *) echo -e \" ${RED}●${NC} Ngrok — ${RED}Stopped${NC}\" ;;\n esac\n\n # Redis\n if systemctl is-active --quiet redis-server 2>/dev/null || pgrep -x redis-server &>/dev/null; then\n echo -e \" ${GREEN}●${NC} Redis — ${GREEN}Running${NC}\"\n else\n echo -e \" ${RED}●${NC} Redis — ${RED}Stopped${NC}\"\n fi\n\n # PostgreSQL\n if systemctl is-active --quiet postgresql 2>/dev/null || pgrep -x postgres &>/dev/null; then\n echo -e \" ${GREEN}●${NC} PostgreSQL — ${GREEN}Running${NC}\"\n else\n echo -e \" ${RED}●${NC} PostgreSQL — ${RED}Stopped${NC}\"\n fi\n\n echo \"\"\n}\n\n# --- Logs --------------------------------------------------------------------\n\nshow_logs() {\n local service=\"$1\"\n local lines=\"${2:-50}\"\n\n case \"$service\" in\n django|gunicorn|backend)\n if [ -f \"$DJANGO_LOG\" ]; then\n print_header \"Django/Gunicorn Logs\"\n tail -f -n \"$lines\" \"$DJANGO_LOG\"\n else\n print_error \"No Django logs found. Is the service running?\"\n echo \" Expected log file: $DJANGO_LOG\"\n fi\n ;;\n celery|worker)\n if [ -f \"$CELERY_LOG\" ]; then\n print_header \"Celery Worker Logs\"\n tail -f -n \"$lines\" \"$CELERY_LOG\"\n else\n print_error \"No Celery logs found. Is the service running?\"\n echo \" Expected log file: $CELERY_LOG\"\n fi\n ;;\n frontend|nginx|web)\n print_header \"Nginx/Frontend Logs\"\n if [ -f \"$NGINX_ACCESS_LOG\" ] && [ -f \"$NGINX_ERROR_LOG\" ]; then\n sudo tail -f -n \"$lines\" \"$NGINX_ACCESS_LOG\" \"$NGINX_ERROR_LOG\"\n elif [ -f \"$NGINX_ACCESS_LOG\" ]; then\n sudo tail -f -n \"$lines\" \"$NGINX_ACCESS_LOG\"\n elif [ -f \"$NGINX_ERROR_LOG\" ]; then\n sudo tail -f -n \"$lines\" \"$NGINX_ERROR_LOG\"\n else\n print_error \"No Nginx logs found. Is Nginx running?\"\n fi\n ;;\n ngrok|tunnel)\n if [ -f \"$NGROK_LOG\" ]; then\n print_header \"Ngrok Tunnel Logs\"\n tail -f -n \"$lines\" \"$NGROK_LOG\"\n else\n print_error \"No Ngrok logs found. Is the tunnel running?\"\n echo \" Expected log file: $NGROK_LOG\"\n fi\n ;;\n all)\n print_header \"All Service Logs (combined)\"\n tail -f -n \"$lines\" \\\n \"$DJANGO_LOG\" \\\n \"$CELERY_LOG\" \\\n \"$NGROK_LOG\" \\\n 2>/dev/null &\n TAIL_PID=$!\n sudo tail -f -n \"$lines\" \\\n \"$NGINX_ACCESS_LOG\" \\\n \"$NGINX_ERROR_LOG\" \\\n 2>/dev/null &\n NGINX_TAIL_PID=$!\n # Trap Ctrl+C to kill both tail processes\n trap \"kill $TAIL_PID $NGINX_TAIL_PID 2>/dev/null; exit 0\" INT\n wait\n ;;\n *)\n print_error \"Unknown service: '$service'\"\n echo \"\"\n echo \" Available services:\"\n echo -e \" ${CYAN}django${NC} — Django/Gunicorn backend logs\"\n echo -e \" ${CYAN}celery${NC} — Celery background worker logs\"\n echo -e \" ${CYAN}frontend${NC} — Nginx access & error logs\"\n echo -e \" ${CYAN}ngrok${NC} — Ngrok tunnel logs\"\n echo -e \" ${CYAN}all${NC} — All logs combined\"\n echo \"\"\n echo \" Usage: ./deploy_baraka.sh logs <service>\"\n exit 1\n ;;\n esac\n}\n\n# --- PostgreSQL Setup -------------------------------------------------------\n\nsetup_postgres() {\n sudo systemctl start postgresql 2>/dev/null || true\n psql_su() { (cd /tmp && sudo -u postgres psql \"$@\"); }\n echo \" Creating role tlk@tlk...\"\n psql_su -tc \"SELECT 1 FROM pg_roles WHERE rolname='tlk@tlk'\" | grep -q 1 \\\n && echo \" Role already exists\" \\\n || psql_su -c \"CREATE ROLE \\\"tlk@tlk\\\" LOGIN PASSWORD 'tlk_vesta_1680';\"\n echo \" Creating database baraka_db...\"\n psql_su -tc \"SELECT 1 FROM pg_database WHERE datname='baraka_db'\" | grep -q 1 \\\n && echo \" Database already exists\" \\\n || psql_su -c \"CREATE DATABASE baraka_db OWNER \\\"tlk@tlk\\\";\"\n echo \" Granting privileges...\"\n psql_su -c \"GRANT ALL PRIVILEGES ON DATABASE baraka_db TO \\\"tlk@tlk\\\";\"\n psql_su -d baraka_db -c \"ALTER SCHEMA public OWNER TO \\\"tlk@tlk\\\";\"\n echo -e \" ${GREEN}✅${NC} PostgreSQL setup complete (user: tlk@tlk, db: baraka_db)\"\n}\n\n# --- Full Deployment (Install + Setup) --------------------------------------\n\nfull_deploy() {\n set -e\n print_header \"Full Deployment (Install + Start)\"\n\n # 1. System Package Updates\n print_step \"🔄 [1/10] Updating Ubuntu System Package Repository...\"\n sudo apt-get update -y\n\n # 2. Dependency Installation\n print_step \"📦 [2/10] Installing Core Dependencies (Python, PostgreSQL, Redis, Nginx, Git)...\"\n sudo apt-get install -y python3-pip python3-venv postgresql postgresql-contrib redis-server nginx git curl libpq-dev build-essential\n\n # 3. Redis & PostgreSQL Auto-Start\n print_step \"⚡ [3/10] Starting and configuring core system services...\"\n sudo systemctl enable redis-server\n sudo systemctl start redis-server\n sudo systemctl enable postgresql\n sudo systemctl start postgresql\n\n # 4. PostgreSQL Database Creation\n print_step \"🗄️ [4/10] Setting up PostgreSQL production database 'baraka_db'...\"\n setup_postgres\n\n # 5. Virtual Environment & Dependencies\n print_step \"🐍 [5/10] Setting up Python virtual environment & packages...\"\n cd \"$SCRIPT_DIR\"\n if [ ! -d \"venv\" ]; then\n python3 -m venv venv\n fi\n ./venv/bin/pip install --upgrade pip\n ./venv/bin/pip install -r requirements.txt\n\n # 6. Environment Configurations\n print_step \"📝 [6/10] Checking Environment Variables (.env)...\"\n if [ ! -f \".env\" ]; then\n cp .env.example .env\n echo \" ✅ Generated .env from .env.example.\"\n else\n echo \" ✅ .env already exists.\"\n fi\n\n # 7. Django DB Migrations & Static Files\n print_step \"🚀 [7/10] Running schema migrations and building production tables...\"\n ./venv/bin/python manage.py migrate\n ./venv/bin/python manage.py collectstatic --noinput\n\n # 8. Setup Nginx Reverse Proxy\n print_step \"🌐 [8/10] Configuring Nginx web server for Reverse Proxy...\"\n # Make entire path to frontend traversable by nginx (www-data)\n local dir=\"$SCRIPT_DIR\"\n while [ \"$dir\" != \"/\" ]; do\n chmod o+x \"$dir\" 2>/dev/null || true\n dir=\"$(dirname \"$dir\")\"\n done\n chmod -R o+rX \"$SCRIPT_DIR/frontend\" 2>/dev/null || true\n\n NGINX_CONF=\"/etc/nginx/sites-available/baraka\"\n sudo tee $NGINX_CONF > /dev/null <<EOF\nserver {\n listen 80;\n server_name _;\n\n # Static Frontend\n location / {\n root $SCRIPT_DIR/frontend;\n index index.html;\n try_files \\$uri \\$uri/ /index.html;\n }\n\n # API Backend Reverse Proxy\n location /api/ {\n proxy_pass http://127.0.0.1:8003/api/;\n proxy_set_header Host \\$host;\n proxy_set_header X-Real-IP \\$remote_addr;\n proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;\n proxy_set_header X-Forwarded-Proto \\$scheme;\n }\n\n # Media Files (served directly by nginx, not proxied to Django)\n location /media/ {\n alias $SCRIPT_DIR/media/;\n }\n}\nEOF\n\n sudo ln -sf $NGINX_CONF /etc/nginx/sites-enabled/\n sudo rm -f /etc/nginx/sites-enabled/default || true\n sudo systemctl restart nginx\n\n # 9. Install & Configure Ngrok\n print_step \"🚇 [9/10] Installing and configuring Ngrok Tunnel...\"\n if ! command -v ngrok &> /dev/null; then\n curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null\n echo \"deb https://ngrok-agent.s3.amazonaws.com buster main\" | sudo tee /etc/apt/sources.list.d/ngrok.list\n sudo apt-get update -y\n sudo apt-get install -y ngrok\n else\n echo \" Ngrok is already installed.\"\n fi\n\n # Prompt user for ngrok auth token\n echo \"\"\n echo -e \"${CYAN}🔑 Ngrok Authentication${NC}\"\n echo -e \" Get your token from: ${BOLD}https://dashboard.ngrok.com/get-started/your-authtoken${NC}\"\n echo \"\"\n read -rp \" Enter your Ngrok auth token: \" NGROK_TOKEN\n if [ -z \"$NGROK_TOKEN\" ]; then\n print_warn \"No Ngrok token provided. Skipping Ngrok auth configuration.\"\n print_warn \"You can configure it later with: ngrok config add-authtoken YOUR_TOKEN\"\n else\n ngrok config add-authtoken \"$NGROK_TOKEN\"\n echo -e \" ${GREEN}✅${NC} Ngrok auth token configured.\"\n fi\n\n # 10. Start all services in background\n print_step \"⚙️ [10/10] Starting all services in background...\"\n ensure_dirs\n start_nginx\n start_django\n start_celery\n start_ngrok\n\n echo \"\"\n echo -e \"${CYAN}=========================================================================${NC}\"\n echo -e \"${BOLD} ✨ Baraka SaaS Platform Deployment Completed Successfully!${NC}\"\n echo -e \"${CYAN}=========================================================================${NC}\"\n echo \"\"\n echo -e \" ${GREEN}●${NC} All services are running in the background\"\n echo \"\"\n echo -e \" ${BOLD}Commands:${NC}\"\n echo -e \" ${CYAN}./deploy_baraka.sh status${NC} — Check all service statuses\"\n echo -e \" ${CYAN}./deploy_baraka.sh logs django${NC} — View Django logs\"\n echo -e \" ${CYAN}./deploy_baraka.sh logs celery${NC} — View Celery logs\"\n echo -e \" ${CYAN}./deploy_baraka.sh logs frontend${NC} — View Nginx logs\"\n echo -e \" ${CYAN}./deploy_baraka.sh logs ngrok${NC} — View Ngrok logs\"\n echo -e \" ${CYAN}./deploy_baraka.sh logs all${NC} — View all logs\"\n echo -e \" ${CYAN}./deploy_baraka.sh stop${NC} — Stop all services\"\n echo -e \" ${CYAN}./deploy_baraka.sh restart${NC} — Restart all services\"\n echo \"\"\n}\n\n# --- Main Entry Point --------------------------------------------------------\n\nCOMMAND=\"${1:-deploy}\"\nSERVICE=\"$2\"\n\ncase \"$COMMAND\" in\n deploy|install|setup)\n full_deploy\n ;;\n baraka)\n print_header \"First-Time PostgreSQL Setup + Migrations\"\n ensure_dirs\n setup_postgres\n cd \"$SCRIPT_DIR\"\n if [ ! -d \"venv\" ]; then\n python3 -m venv venv\n fi\n ./venv/bin/pip install --upgrade pip\n ./venv/bin/pip install -r requirements.txt\n if [ ! -f \".env\" ]; then\n cp .env.example .env\n fi\n print_step \"📦 Running makemigrations...\"\n ./venv/bin/python manage.py makemigrations\n print_step \"🗄️ Running migrate...\"\n ./venv/bin/python manage.py migrate\n echo \"\"\n echo -e \"${GREEN}✅ Baraka database setup complete.${NC}\"\n echo \"\"\n ;;\n start)\n start_all\n ;;\n stop)\n stop_all\n ;;\n restart)\n stop_all\n start_all\n ;;\n status)\n check_status\n ;;\n logs|log)\n if [ -z \"$SERVICE\" ]; then\n print_error \"Please specify a service to view logs for.\"\n echo \"\"\n echo \" Usage: ./deploy_baraka.sh logs <service>\"\n echo \"\"\n echo \" Available services:\"\n echo -e \" ${CYAN}django${NC} — Django/Gunicorn backend logs\"\n echo -e \" ${CYAN}celery${NC} — Celery background worker logs\"\n echo -e \" ${CYAN}frontend${NC} — Nginx access & error logs\"\n echo -e \" ${CYAN}ngrok${NC} — Ngrok tunnel logs\"\n echo -e \" ${CYAN}all${NC} — All logs combined\"\n exit 1\n fi\n show_logs \"$SERVICE\"\n ;;\n help|-h|--help)\n echo \"\"\n echo -e \"${BOLD}Baraka Deployment Script${NC}\"\n echo \"\"\n echo \"Usage: ./deploy_baraka.sh [command] [options]\"\n echo \"\"\n echo \"Commands:\"\n echo -e \" ${CYAN}deploy${NC} Full deployment (install deps + configure + start)\"\n echo -e \" ${CYAN}baraka${NC} First-time Postgres setup (user, db, migrations)\"\n echo -e \" ${CYAN}start${NC} Start all background services\"\n echo -e \" ${CYAN}stop${NC} Stop all background services\"\n echo -e \" ${CYAN}restart${NC} Restart all background services\"\n echo -e \" ${CYAN}status${NC} Show status of all services\"\n echo -e \" ${CYAN}logs <service>${NC} Tail logs for a service (django|celery|frontend|ngrok|all)\"\n echo -e \" ${CYAN}help${NC} Show this help message\"\n echo \"\"\n ;;\n *)\n print_error \"Unknown command: '$COMMAND'\"\n echo \" Run ${CYAN}./deploy_baraka.sh help${NC} to see available commands.\"\n exit 1\n ;;\nesac\n"}}, "docker-compose.yml": {"8def255a88b52b53c7519283d825274e2e7e0f9f": {"t": 1785604653.229084, "n": 1692, "h": "5ed45b82a1ae3644", "c": "version: '3.8'\n\nservices:\n db:\n image: postgres:15-alpine\n container_name: baraka_db\n ports:\n - \"5432:5432\"\n environment:\n - POSTGRES_DB=baraka\n - POSTGRES_USER=postgres\n - POSTGRES_PASSWORD=barakasecurepass\n volumes:\n - postgres_data:/var/lib/postgresql/data\n healthcheck:\n test: [\"CMD-SHELL\", \"pg_isready -U postgres\"]\n interval: 5s\n timeout: 5s\n retries: 5\n\n redis:\n image: redis:alpine\n container_name: baraka_redis\n ports:\n - \"6379:6379\"\n\n backend:\n build: .\n container_name: baraka_backend\n command: >\n sh -c \"python manage.py migrate &&\n gunicorn backend.wsgi:application --bind 0.0.0.0:8000 --workers 4 --threads 2 --timeout 120\"\n ports:\n - \"8000:8000\"\n environment:\n - DB_HOST=db\n - DB_NAME=baraka\n - DB_USER=postgres\n - DB_PASSWORD=barakasecurepass\n - REDIS_URL=redis://redis:6379/1\n - CELERY_BROKER_URL=redis://redis:6379/1\n depends_on:\n db:\n condition: service_healthy\n redis:\n condition: service_started\n\n celery_worker:\n build: .\n container_name: baraka_celery_worker\n command: celery -A backend worker --loglevel=info\n environment:\n - DB_HOST=db\n - DB_NAME=baraka\n - DB_USER=postgres\n - DB_PASSWORD=barakasecurepass\n - REDIS_URL=redis://redis:6379/1\n - CELERY_BROKER_URL=redis://redis:6379/1\n depends_on:\n db:\n condition: service_healthy\n redis:\n condition: service_started\n\n frontend:\n build: ./frontend\n container_name: baraka_frontend\n ports:\n - \"8080:80\"\n depends_on:\n - backend\n\nvolumes:\n postgres_data:\n"}}, "local.sh": {"21f972a863f8bc8431080788ef0fb99c2e26aa10": {"t": 1785604654.9000242, "n": 501, "h": "cc0762e2bb3bbb23", "c": "#!/bin/bash\n# ===================================================\n# 📦 Baraka SaaS Platform Local Workspace Launcher (POSIX)\n# ===================================================\n\necho \"===================================================\"\necho \" 🚀 Starting Baraka Local Services...\"\necho \"===================================================\"\necho \"\"\n\n# Activate virtual environment if available, then start the runner\nif [ -d \"venv\" ]; then\n source venv/bin/activate\nfi\n\npython3 local_runner.py\n\n"}}, "local_runner.py": {"b767051357e05e023a49750507970254adc5fbe8": {"t": 1785604656.704201, "n": 5229, "h": "4c9dacf491e6fa20", "c": "import subprocess\nimport sys\nimport time\nimport os\nimport signal\nimport shutil\n\nIS_WINDOWS = os.name == 'nt'\n\n# Parse .env file for active services\ndb_host_active = False\nredis_active = False\n\nif os.path.exists(\".env\"):\n try:\n with open(\".env\", \"r\", encoding=\"utf-8\") as f:\n for line in f:\n line = line.strip()\n if line.startswith(\"DB_HOST=\") and not line.startswith(\"#\"):\n db_host_active = True\n elif (line.startswith(\"REDIS_URL=\") or line.startswith(\"CELERY_BROKER_URL=\")) and not line.startswith(\"#\"):\n redis_active = True\n except Exception as e:\n print(f\"⚠️ Could not parse .env configuration: {e}\")\n\n# Build command list depending on OS platform and .env configuration\ncommands_to_run = []\n\n# 1. Redis Server\nif redis_active:\n if IS_WINDOWS:\n if shutil.which(\"redis-server\"):\n commands_to_run.append((\"Redis\", \"redis-server\"))\n else:\n print(\"ℹ️ [Info] 'redis-server' was not found in PATH. Assuming Memurai/Redis is running as a background Windows service.\\n\")\n else:\n if shutil.which(\"redis-server\"):\n commands_to_run.append((\"Redis\", \"redis-server\"))\n else:\n print(\"⚠️ [Warning] Redis is active in .env but 'redis-server' was not found in PATH. Celery might fail to connect.\\n\")\nelse:\n print(\"ℹ️ [Info] Redis is commented out in .env. Skipping Redis (falling back to local memory cache).\\n\")\n\n# 2. PostgreSQL Service\nif db_host_active:\n if IS_WINDOWS:\n commands_to_run.append((\"PostgreSQL\", \"net start postgresql-x64-18\"))\n else:\n has_systemctl = os.path.exists(\"/bin/systemctl\") or os.path.exists(\"/usr/bin/systemctl\")\n commands_to_run.append((\"PostgreSQL\", \"sudo systemctl start postgresql\" if has_systemctl else \"echo PostgreSQL assumed running\"))\nelse:\n print(\"ℹ️ [Info] DB_HOST is commented out in .env. Skipping PostgreSQL (falling back to SQLite database).\\n\")\n\n# 3. Django Backend\ndjango_cmd = \"venv\\\\Scripts\\\\python.exe manage.py runserver 0.0.0.0:8000\" if IS_WINDOWS else \"./venv/bin/python manage.py runserver 0.0.0.0:8000\"\ncommands_to_run.append((\"Django Backend\", django_cmd))\n\n# 4. Celery Worker (Only run if Redis is active in .env)\nif redis_active:\n celery_found = False\n celery_cmd = \"\"\n if IS_WINDOWS:\n if shutil.which(\"venv\\\\Scripts\\\\celery.exe\") or shutil.which(\"celery\"):\n celery_cmd = \"venv\\\\Scripts\\\\celery.exe -A backend worker --loglevel=info -P solo\"\n celery_found = True\n else:\n if os.path.exists(\"./venv/bin/celery\") or shutil.which(\"celery\"):\n celery_cmd = \"./venv/bin/celery -A backend worker --loglevel=info\"\n celery_found = True\n \n if celery_found:\n commands_to_run.append((\"Celery Worker\", celery_cmd))\n else:\n print(\"⚠️ [Warning] Celery was not found in path/virtualenv. Skipping Celery worker.\\n\")\nelse:\n print(\"ℹ️ [Info] Celery is not active in .env. Skipping Celery background workers (using Celery Eager tasks).\\n\")\n\n# 5. Frontend Static Server\nfrontend_cmd = \"python -m http.server 8080 --directory frontend\" if IS_WINDOWS else \"python3 -m http.server 8080 --directory frontend\"\ncommands_to_run.append((\"Frontend Static\", frontend_cmd))\n\nprocesses = []\n\ndef cleanup(sig, frame):\n print(\"\\n🛑 Shutting down all Baraka services...\")\n for name, p in processes:\n print(f\"Stopping {name} (PID: {p.pid})...\")\n try:\n if IS_WINDOWS:\n # Force kill the process tree on Windows to ensure no orphaned child processes\n subprocess.run(f\"taskkill /F /T /PID {p.pid}\", shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)\n else:\n # Send SIGTERM to the process group to clean up shell child processes on Unix\n os.killpg(os.getpgid(p.pid), signal.SIGTERM)\n except Exception:\n try:\n p.terminate()\n except Exception:\n pass\n print(\"✅ All services stopped. Goodbye!\")\n sys.exit(0)\n\n# Register interrupt signals\nsignal.signal(signal.SIGINT, cleanup)\nsignal.signal(signal.SIGTERM, cleanup)\n\nprint(\"===================================================\")\nprint(\" 📦 Baraka SaaS Platform Local Workspace Runner\")\nprint(\" Running all services in a single console tab...\")\nprint(\"===================================================\\n\")\n\nfor name, cmd in commands_to_run:\n print(f\"🚀 Starting {name}...\")\n try:\n if IS_WINDOWS:\n p = subprocess.Popen(cmd, shell=True)\n else:\n p = subprocess.Popen(cmd, shell=True, preexec_fn=os.setsid)\n processes.append((name, p))\n except Exception as e:\n print(f\"❌ Failed to start {name}: {e}\")\n time.sleep(1.5) # Pause to let the service bind/start\n\nprint(\"\\n===================================================\")\nprint(\" 🔥 All services running in this tab!\")\nprint(\" ⚠️ Press [Ctrl+C] to STOP ALL SERVICES at once.\")\nprint(\"===================================================\\n\")\n\n# Keep main thread alive\ntry:\n while True:\n time.sleep(1)\nexcept KeyboardInterrupt:\n cleanup(None, None)\n"}}, "manage.py": {"eb6431e2c0b15d12a46e1e435facbc8484b6f0ac": {"t": 1785604659.8706105, "n": 663, "h": "f93f671cf733135a", "c": "#!/usr/bin/env python\n\"\"\"Django's command-line utility for administrative tasks.\"\"\"\nimport os\nimport sys\n\n\ndef main():\n \"\"\"Run administrative tasks.\"\"\"\n os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')\n try:\n from django.core.management import execute_from_command_line\n except ImportError as exc:\n raise ImportError(\n \"Couldn't import Django. Are you sure it's installed and \"\n \"available on your PYTHONPATH environment variable? Did you \"\n \"forget to activate a virtual environment?\"\n ) from exc\n execute_from_command_line(sys.argv)\n\n\nif __name__ == '__main__':\n main()\n"}}, "vercel.json": {"0d7c7af80ace525a3f0c585b0570fee06889e82f": {"t": 1785604661.4767566, "n": 570, "h": "97f7b12c80242d13", "c": "{\n \"version\": 2,\n \"cleanUrls\": true,\n \"builds\": [\n {\n \"src\": \"frontend/**/*\",\n \"use\": \"@vercel/static\"\n },\n {\n \"src\": \"index.html\",\n \"use\": \"@vercel/static\"\n },\n {\n \"src\": \"backend/wsgi.py\",\n \"use\": \"@vercel/python\"\n }\n ],\n \"rewrites\": [\n {\n \"source\": \"/api/:path*\",\n \"destination\": \"/backend/wsgi.py\"\n },\n {\n \"source\": \"/admin/:path*\",\n \"destination\": \"/backend/wsgi.py\"\n },\n {\n \"source\": \"/(css|js|images|html)/:path*\",\n \"destination\": \"/frontend/$1/:path*\"\n }\n ]\n}\n"}}}}