Files
homaroma/serverinfo/192.168.1.26/README.md
T
2026-10-17 13:34:07 +07:00

9.0 KiB

Server Information: sql@192.168.1.26

เอกสารสรุปรายละเอียดสภาพแวดล้อม (Environment), Runtimes (Node, Bun, PM2), ฐานข้อมูล (PostgreSQL, MariaDB), Nginx, และข้อกำหนดสำหรับการเขียน Git post-receive hook บนเซิร์ฟเวอร์ 192.168.1.26


1. ข้อมูลระบบทั่วไป (System Overview)

รายการ รายละเอียด
IP Address 192.168.1.26
Hostname sql
SSH User sql (uid=1000, gid=1000)
Home Directory /home/sql
OS Ubuntu 22.04.5 LTS (Jammy Jellyfish)
Kernel Linux 5.15.0-191-generic x86_64
CPU 12 vCPUs (QEMU Virtual CPU version 2.5+)
RAM Total: 15 GiB (Used: ~1.7 GiB, Available: ~13 GiB, Swap: 4.0 GiB)
Disk / (LVM ubuntu--vg-ubuntu--lv): 391 GiB (Used: 44 GiB / 12%, Avail: 331 GiB)
User Groups sql (1000), adm (4), cdrom (24), sudo (27), dip (30), plugdev (46), lxd (110)
Sudo Access ต้องการ Password (Non-interactive sudo ไม่สามารถรันแบบไร้รหัสผ่านได้)

2. สรุป Runtimes & เครื่องมือสำหรับ Post-Receive Hook

ข้อควรระวังสำคัญสำหรับ Post-Receive Hook: เมื่อ Git รัน hook ผ่าน SSH (non-login non-interactive shell), ค่า $PATH จะถูกจำกัดเป็นค่าเริ่มต้นของระบบ (มักมีแค่ /usr/bin:/bin) ทำให้หา bun ไม่เจอ ต้อง export PATH เสมอที่ต้นสคริปต์ hook:

export PATH="/home/sql/.bun/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
เครื่องมือ Version Path แบบ Absolute หมายเหตุ
Bun 1.3.8 /home/sql/.bun/bin/bun รันเร็ว เหมาะสำหรับ bun install, bun run build, และ Elysia/Backend
Node.js v25.2.0 /usr/bin/node ระบบไม่ได้ใช้ NVM (ลงผ่าน Package Manager ไว้ที่ /usr/bin/node)
NPM 11.6.2 /usr/bin/npm
PM2 6.0.14 /usr/bin/pm2 มี Systemd Service pm2-sql.service เปิดใช้งานอัตโนมัติ (Boot startup)
Git 2.34.1 /usr/bin/git
Python 3.10.12 /usr/bin/python3 มี venv อยู่ในบางโปรเจกต์

3. สถานะ PM2 & โปรเซสที่กำลังทำงานอยู่ (PM2 Processes)

PM2 Service: pm2-sql (Active / Enabled on boot)

ID Process Name Mode Interpreter Script / Entry Point Working Directory (CWD) Port / Usage
0 pm2-logrotate module node - - Auto-rotate logs
1 ddc hr backend fork /home/sql/.bun/bin/bun apps/backend/dist/index.js /home/sql/code/ddc_ops/apps/backend 5000
2 aroka-backend fork none (Bun directly) /home/sql/.bun/bin/bun run ... /home/sql/code/aro/apps/backend 4000
3 shop-ddcth fork node (v25.2.0) apps/shop.ddcth.com/server.js /home/sql/code/ddc_ops/apps/shop.ddcth.com 3001 (Next.js Standalone)
4 rebrand-dev fork none (bash) bun run dev -- --port 4545 /home/sql/code/rebrand 4545 (Vite Dev Server)
5 check-order-production fork bash run_backend.sh (uvicorn FastAPI) /home/sql/code/nick/check-order-production 8000

4. ฐานข้อมูล (PostgreSQL & MariaDB)

PostgreSQL (Local Instance)

  • Version: PostgreSQL 14.24 (Ubuntu 14.24-0ubuntu0.22.04.1)
  • Cluster: 14/main (Status: online)
  • Port: 5432 (Listen on 127.0.0.1:5432)
  • Local Connection URL (ผ่านการทดสอบสำเร็จ):
    postgresql://postgres:password@localhost:5432/postgres
    
  • ฐานข้อมูลที่มีอยู่ปัจจุบัน:
    • arokamwedweb (Owner: postgres)
    • postgres (Owner: postgres)
  • การสร้าง Database ใหม่สำหรับระบบ CMS:
    psql 'postgresql://postgres:password@localhost:5432/postgres' -c "CREATE DATABASE homaroma_db;"
    
    Connection string สำหรับ .env:
    DATABASE_URL="postgresql://postgres:password@localhost:5432/homaroma_db?schema=public"
    

MariaDB / MySQL

  • Version: 10.6.22-MariaDB
  • Port: 3306 (Listen on 0.0.0.0:3306)
  • Status: Active (running)

5. แผนผังพอร์ตที่ใช้งานอยู่บน Server (Port Allocation Map)

ห้ามตั้งพอร์ตซ้ำกับเซอร์วิสเหล่านี้ในการ Deploy:

Port Protocol / Service Process / Application
22 SSH OpenSSH Server
80 HTTP Nginx Reverse Proxy & Web Server
3001 HTTP shop-ddcth (Next.js SSR / Standalone)
3306 MySQL MariaDB 10.6
4000 HTTP aroka-backend (Bun API)
4545 HTTP rebrand-dev (Vite dev)
5000 HTTP ddc hr backend (Bun Elysia API)
5432 PostgreSQL PostgreSQL 14
6333 / 6334 HTTP / gRPC Qdrant Vector Database
8000 HTTP check-order-production (FastAPI / Uvicorn)

💡 พอร์ตแนะนำสำหรับระบบใหม่บน Server นี้:

  • Backend API (Elysia/Node): 3005 หรือ 3050
  • Website (Next.js SSR): 3002 หรือ 3003 (พอร์ต 3002 ว่างอยู่)

6. สิทธิ์และการจัดเก็บไฟล์ (Filesystem Structure & Permissions)

1) Git Bare Repositories

  • ตำแหน่งจัดเก็บ: /home/sql/git/<project-name>.git
  • Repositories บนเครื่อง:
    • /home/sql/git/bigbike.git (Symlink: bigbike.ddcsprocket.com.git) ⚡ [สร้างใหม่สำหรับ bigbike.ddcsprocket.com]
    • /home/sql/git/aro.git
    • /home/sql/git/ddc_ops.git
    • /home/sql/git/rebrand.git

2) Checked-out Code & Backend Run Dir

  • ตำแหน่งจัดเก็บ: /home/sql/code/<project-name>/
  • ตัวอย่างที่มีอยู่เดิม:
    • /home/sql/code/ddc_ops
    • /home/sql/code/aro
    • /home/sql/code/rebrand

3) Web Root สำหรับ Static Files (Nginx)

  • Root: /var/www/html/
  • สิทธิ์การเขียน:
    • โฟลเดอร์ /var/www/html หลักเป็นของ root:root (User sql ไม่สามารถ mkdir ใต้ /var/www/html โดยตรงได้)
    • ต้องให้ root สร้างโฟลเดอร์ไว้ล่วงหน้าและตั้งสิทธิ์เป็น sql:sql เช่น:
      sudo mkdir -p /var/www/html/homaroma
      sudo chown -R sql:sql /var/www/html/homaroma
      
    • หรือเลือก Deploy static files ไว้ภายใน /home/sql/projects/... แล้วให้ Nginx ชี้เข้ามา (ต้องเปิด permission ให้อ่านได้)

7. Nginx Virtual Hosts ที่ตั้งค่าไว้ปัจจุบัน

Nginx รันอยู่ที่พอร์ต 80 โดยมี vhosts ใน /etc/nginx/sites-enabled/:

  • admindemo.arokathaimed.com ➔ /var/www/html/aroka_admin
  • demo.arokathaimed.com ➔ /var/www/html/arokamedweb
  • ops.ddcth.com & Default Server ➔ /var/www/html/ddc_ops
  • luckydraw.ddcth.com ➔ /var/www/html/luckydraw
  • shop.ddcsprocket.co.th ➔ /var/www/html/shop.ddcth.com

8. ข้อสรุปและ Checklist สำหรับสร้าง Post-Receive Hook

  1. ระบุ Binary Paths ชัดเจน:
    BUN="/home/sql/.bun/bin/bun"
    PM2="/usr/bin/pm2"
    NODE="/usr/bin/node"
    export PATH="/home/sql/.bun/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
    
  2. สร้าง Git Bare Repo:
    mkdir -p /home/sql/git/cms.git
    cd /home/sql/git/cms.git
    git init --bare
    
  3. เตรียม Directory สำหรับ Code:
    mkdir -p /home/sql/code/cms
    
  4. เตรียม Directory สำหรับ Static Deploy (SPA/Admin):
    # ต้องสร้างด้วยสิทธิ์ที่ sql สามารถเขียนได้
    mkdir -p /var/www/html/cms_spa /var/www/html/cms_admin
    
  5. สร้างไฟล์ hook ที่ /home/sql/git/<repo>.git/hooks/post-receive และ chmod +x