Spaces:
Running
Running
Update run.sh
Browse files
run.sh
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
set -e
|
| 3 |
|
| 4 |
-
# --- Cấu hình Biến Môi trường
|
| 5 |
-
#
|
|
|
|
| 6 |
export APP_KEY="your-secret-key-changeme"
|
| 7 |
export DB_HOST="localhost"
|
| 8 |
export DB_PORT="5432"
|
|
@@ -10,51 +11,32 @@ export DB_DATABASE="nocobase_db"
|
|
| 10 |
export DB_USER="nocobase_user"
|
| 11 |
export DB_PASSWORD="nocobase_password"
|
| 12 |
export TZ="UTC"
|
| 13 |
-
# Đặt cổng ứng dụng NocoBase
|
| 14 |
export APP_PORT="4444"
|
| 15 |
|
| 16 |
# --- 1. Khởi động PostgreSQL ---
|
| 17 |
echo "Starting PostgreSQL..."
|
| 18 |
-
# Khởi động service postgresql
|
| 19 |
service postgresql start
|
| 20 |
-
|
| 21 |
-
# Chờ PostgreSQL sẵn sàng nhận kết nối
|
| 22 |
echo "Waiting for PostgreSQL to be ready..."
|
| 23 |
-
until su - postgres -c "pg_isready"; do
|
| 24 |
-
sleep 1
|
| 25 |
-
done
|
| 26 |
-
|
| 27 |
-
# --- 2. Tạo Database và User cho NocoBase ---
|
| 28 |
-
echo "Checking/Creating database and user..."
|
| 29 |
-
# Kiểm tra xem user đã tồn tại chưa, nếu chưa thì tạo mới
|
| 30 |
-
if ! su - postgres -c "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'\"" | grep -q 1; then
|
| 31 |
-
echo "Creating user $DB_USER..."
|
| 32 |
-
su - postgres -c "psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';\""
|
| 33 |
-
else
|
| 34 |
-
echo "User $DB_USER already exists."
|
| 35 |
-
fi
|
| 36 |
|
| 37 |
-
# Kiểm tra
|
| 38 |
if ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw "$DB_DATABASE"; then
|
| 39 |
-
echo "
|
| 40 |
-
su - postgres -c "psql -c \"CREATE
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# Kiểm tra nếu thư mục my-nocobase chưa tồn tại thì mới clone
|
| 47 |
-
if [ ! -d "my-nocobase" ]; then
|
| 48 |
-
echo "Cloning NocoBase repository..."
|
| 49 |
-
git clone https://github.com/nocobase/nocobase.git -b main --depth=1 my-nocobase
|
| 50 |
fi
|
| 51 |
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
#
|
| 56 |
-
echo "Creating .env file..."
|
| 57 |
cat <<EOF > .env
|
|
|
|
| 58 |
APP_KEY=$APP_KEY
|
| 59 |
DB_HOST=$DB_HOST
|
| 60 |
DB_PORT=$DB_PORT
|
|
@@ -65,17 +47,5 @@ TZ=$TZ
|
|
| 65 |
APP_PORT=$APP_PORT
|
| 66 |
EOF
|
| 67 |
|
| 68 |
-
|
| 69 |
-
if [ ! -d "node_modules" ]; then
|
| 70 |
-
echo "Installing dependencies (this may take a while)..."
|
| 71 |
-
yarn install --frozen-lockfile
|
| 72 |
-
fi
|
| 73 |
-
|
| 74 |
-
# Cài đặt NocoBase (khởi tạo bảng trong DB, v.v.)
|
| 75 |
-
echo "Installing NocoBase tables..."
|
| 76 |
-
yarn nocobase install --lang=en-US
|
| 77 |
-
|
| 78 |
-
# --- 4. Khởi động NocoBase ---
|
| 79 |
-
echo "Starting NocoBase in development mode on port $APP_PORT..."
|
| 80 |
-
# Chạy ở cổng APP_PORT và lắng nghe trên tất cả các interface (0.0.0.0)
|
| 81 |
exec yarn dev --port $APP_PORT --host 0.0.0.0
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
|
| 4 |
+
# --- Cấu hình Biến Môi trường ---
|
| 5 |
+
# --- THÊM DB_DIALECT VÀO ĐÂY ---
|
| 6 |
+
export DB_DIALECT="postgres"
|
| 7 |
export APP_KEY="your-secret-key-changeme"
|
| 8 |
export DB_HOST="localhost"
|
| 9 |
export DB_PORT="5432"
|
|
|
|
| 11 |
export DB_USER="nocobase_user"
|
| 12 |
export DB_PASSWORD="nocobase_password"
|
| 13 |
export TZ="UTC"
|
|
|
|
| 14 |
export APP_PORT="4444"
|
| 15 |
|
| 16 |
# --- 1. Khởi động PostgreSQL ---
|
| 17 |
echo "Starting PostgreSQL..."
|
|
|
|
| 18 |
service postgresql start
|
|
|
|
|
|
|
| 19 |
echo "Waiting for PostgreSQL to be ready..."
|
| 20 |
+
until su - postgres -c "pg_isready"; do sleep 1; done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# --- 2. Kiểm tra DB ---
|
| 23 |
if ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw "$DB_DATABASE"; then
|
| 24 |
+
echo "WARNING: Database not found. Re-initializing..."
|
| 25 |
+
su - postgres -c "psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';\"" || true
|
| 26 |
+
su - postgres -c "psql -c \"CREATE DATABASE $DB_DATABASE OWNER $DB_USER;\"" || true
|
| 27 |
+
cd /app/my-nocobase
|
| 28 |
+
# Đảm bảo DB_DIALECT có mặt khi chạy install lại
|
| 29 |
+
export DB_DIALECT="postgres"
|
| 30 |
+
yarn nocobase install --lang=en-US
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
fi
|
| 32 |
|
| 33 |
+
# --- 3. Chuẩn bị và Chạy NocoBase ---
|
| 34 |
+
cd /app/my-nocobase
|
| 35 |
|
| 36 |
+
echo "Creating .env file for runtime..."
|
| 37 |
+
# --- THÊM DB_DIALECT VÀO FILE .ENV ---
|
|
|
|
| 38 |
cat <<EOF > .env
|
| 39 |
+
DB_DIALECT=$DB_DIALECT
|
| 40 |
APP_KEY=$APP_KEY
|
| 41 |
DB_HOST=$DB_HOST
|
| 42 |
DB_PORT=$DB_PORT
|
|
|
|
| 47 |
APP_PORT=$APP_PORT
|
| 48 |
EOF
|
| 49 |
|
| 50 |
+
echo "Starting NocoBase on port $APP_PORT..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
exec yarn dev --port $APP_PORT --host 0.0.0.0
|