Spaces:
Sleeping
Sleeping
Create run.sh
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081#!/bin/bashset -e # Dừng script ngay nếu có lệnh bị lỗi
# --- Cấu hình Biến Môi trường cho NocoBase & Database ---# Bạn có thể thay đổi APP_KEY bằng một chuỗi ngẫu nhiên an toàn hơnexport APP_KEY="your-secret-key-changeme"export DB_HOST="localhost"export DB_PORT="5432"export DB_DATABASE="nocobase_db"export DB_USER="nocobase_user"export DB_PASSWORD="nocobase_password"export TZ="UTC"# Đặt cổng ứng dụng NocoBaseexport APP_PORT="4444"
# --- 1. Khởi động PostgreSQL ---echo "Starting PostgreSQL..."# Khởi động service postgresqlservice postgresql start
# Chờ PostgreSQL sẵn sàng nhận kết nốiecho "Waiting for PostgreSQL to be ready..."until su - postgres -c "pg_isready"; do sleep 1done
# --- 2. Tạo Database và User cho NocoBase ---echo "Checking/Creating database and user..."# Kiểm tra xem user đã tồn tại chưa, nếu chưa thì tạo mớiif ! su - postgres -c "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'\"" | grep -q 1; then echo "Creating user $DB_USER..." su - postgres -c "psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';\""else echo "User $DB_USER already exists."fi
# Kiểm tra xem database đã tồn tại chưa, nếu chưa thì tạo mớiif ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw "$DB_DATABASE"; then echo "Creating database $DB_DATABASE..." su - postgres -c "psql -c \"CREATE DATABASE $DB_DATABASE OWNER $DB_USER;\""else echo "Database $DB_DATABASE already exists."fi
# --- 3. Cài đặt và chạy NocoBase ---# Kiểm tra nếu thư mục my-nocobase chưa tồn tại thì mới cloneif [ ! -d "my-nocobase" ]; then echo "Cloning NocoBase repository..." git clone https://github.com/nocobase/nocobase.git -b main --depth=1 my-nocobasefi
cd my-nocobase
# Tạo file .env từ các biến môi trường đã thiết lập ở trên# Đảm bảo file .env nằm ở thư mục gốc của dự án NocoBase (my-nocobase/.env)echo "Creating .env file..."cat <<EOF > .envAPP_KEY=$APP_KEYDB_HOST=$DB_HOSTDB_PORT=$DB_PORTDB_DATABASE=$DB_DATABASEDB_USER=$DB_USERDB_PASSWORD=$DB_PASSWORDTZ=$TZAPP_PORT=$APP_PORTEOF
# Cài đặt dependencies nếu chưa có node_modulesif [ ! -d "node_modules" ]; then echo "Installing dependencies (this may take a while)..." yarn install --frozen-lockfilefi
# Cài đặt NocoBase (khởi tạo bảng trong DB, v.v.)echo "Installing NocoBase tables..."yarn nocobase install --lang=en-US
# --- 4. Khởi động NocoBase ---echo "Starting NocoBase in development mode on port $APP_PORT..."# Chạy ở cổng APP_PORT và lắng nghe trên tất cả các interface (0.0.0.0)exec yarn dev --port $APP_PORT --host 0.0.0.0run.shAdded+81