File size: 1,668 Bytes
5d328b1
 
3605d15
 
 
 
 
 
5d328b1
3605d15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d328b1
 
 
3605d15
 
 
 
5d328b1
3605d15
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash

# --- Cấu hình Biến Database ---
DB_USER="gradio_user"
# BẠN NÊN THAY ĐỔI MẬT KHẨU NÀY!
DB_PASS="local_password_123" 
DB_NAME="gradio_db"
DB_PORT="5432"

# 1. Khởi động PostgreSQL
echo "Starting PostgreSQL service..."
service postgresql start

echo "Waiting for PostgreSQL to start (5s)..."
sleep 5

# 2. Khởi tạo Database (Chỉ chạy nếu DB chưa tồn tại)
# Script này chạy với tư cách 'root', vì vậy chúng ta dùng 'su'
# để chuyển sang người dùng 'postgres'
if ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw $DB_NAME; then
    echo "Database $DB_NAME not found. Initializing..."
    su - postgres -c "psql -c \"CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';\""
    su - postgres -c "psql -c \"CREATE DATABASE $DB_NAME OWNER $DB_USER;\""
    echo "Database $DB_NAME and user $DB_USER created."
else
    echo "Database $DB_NAME already exists."
fi

# 3. Khởi động Nginx
echo "Starting Nginx..."
service nginx start

# 4. Khởi động Streamlit (với tư cách user 'pn' an toàn hơn)
echo "Starting Streamlit on port 8501 as user 'pn'..."
# Chuyển sang user 'pn' và chạy trong thư mục app
su - pn -c "cd /home/pn/app && streamlit run app_streamlit.py --server.port 8501 --server.address 0.0.0.0 --server.baseUrlPath /streamlit" &

# 5. Khởi động Gradio/FastAPI (với tư cách user 'pn')
echo "Starting Gradio/FastAPI on port 7860 as user 'pn'..."
# 'exec' để nó trở thành quy trình chính, giữ container chạy
# Chuyển sang user 'pn' và chạy trong thư mục app
exec su - pn -c "cd /home/pn/app && uvicorn app_gradio:app --port 7860 --host 0.0.0.0"