Spaces:
Sleeping
Sleeping
Update run.sh
Browse files
run.sh
CHANGED
|
@@ -1,18 +1,42 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
|
| 3 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
# 1. Khởi động
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
echo "Starting Nginx..."
|
| 7 |
service nginx start
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
echo "Starting Streamlit on port 8501..."
|
| 11 |
-
#
|
| 12 |
-
streamlit run app_streamlit.py --server.port 8501 --server.address 0.0.0.0 --server.baseUrlPath /streamlit &
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
echo "Starting Gradio/FastAPI on port 7860..."
|
| 16 |
-
#
|
| 17 |
-
#
|
| 18 |
-
uvicorn app_gradio:app --port 7860 --host 0.0.0.0
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
|
| 3 |
+
# --- Cấu hình Biến Database ---
|
| 4 |
+
DB_USER="gradio_user"
|
| 5 |
+
# BẠN NÊN THAY ĐỔI MẬT KHẨU NÀY!
|
| 6 |
+
DB_PASS="local_password_123"
|
| 7 |
+
DB_NAME="gradio_db"
|
| 8 |
+
DB_PORT="5432"
|
| 9 |
|
| 10 |
+
# 1. Khởi động PostgreSQL
|
| 11 |
+
echo "Starting PostgreSQL service..."
|
| 12 |
+
service postgresql start
|
| 13 |
+
|
| 14 |
+
echo "Waiting for PostgreSQL to start (5s)..."
|
| 15 |
+
sleep 5
|
| 16 |
+
|
| 17 |
+
# 2. Khởi tạo Database (Chỉ chạy nếu DB chưa tồn tại)
|
| 18 |
+
# Script này chạy với tư cách 'root', vì vậy chúng ta dùng 'su'
|
| 19 |
+
# để chuyển sang người dùng 'postgres'
|
| 20 |
+
if ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw $DB_NAME; then
|
| 21 |
+
echo "Database $DB_NAME not found. Initializing..."
|
| 22 |
+
su - postgres -c "psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';\""
|
| 23 |
+
su - postgres -c "psql -c \"CREATE DATABASE $DB_NAME OWNER $DB_USER;\""
|
| 24 |
+
echo "Database $DB_NAME and user $DB_USER created."
|
| 25 |
+
else
|
| 26 |
+
echo "Database $DB_NAME already exists."
|
| 27 |
+
fi
|
| 28 |
+
|
| 29 |
+
# 3. Khởi động Nginx
|
| 30 |
echo "Starting Nginx..."
|
| 31 |
service nginx start
|
| 32 |
|
| 33 |
+
# 4. Khởi động Streamlit (với tư cách user 'pn' an toàn hơn)
|
| 34 |
+
echo "Starting Streamlit on port 8501 as user 'pn'..."
|
| 35 |
+
# Chuyển sang user 'pn' và chạy trong thư mục app
|
| 36 |
+
su - pn -c "cd /home/pn/app && streamlit run app_streamlit.py --server.port 8501 --server.address 0.0.0.0 --server.baseUrlPath /streamlit" &
|
| 37 |
|
| 38 |
+
# 5. Khởi động Gradio/FastAPI (với tư cách user 'pn')
|
| 39 |
+
echo "Starting Gradio/FastAPI on port 7860 as user 'pn'..."
|
| 40 |
+
# 'exec' để nó trở thành quy trình chính, giữ container chạy
|
| 41 |
+
# Chuyển sang user 'pn' và chạy trong thư mục app
|
| 42 |
+
exec su - pn -c "cd /home/pn/app && uvicorn app_gradio:app --port 7860 --host 0.0.0.0"
|