BIG

 

 

 

1. fastapi 를 시스템 서비스로 등록하여 관리하기 위한 시스템 서비스 등록


shell> vi /etc/systemd/system/fastapi.service

[Unit]
# Description: Service description (e.g., FastAPI application running on Python 3.8)
Description=FastAPI Web Service with Python 3.8 (SCL)
# Requires network to be up before starting
After=network.target

[Service]
# Service execution type, 'simple' is typically used for long-running processes
Type=simple

# User who runs the service (ensures correct file/environment access)
User=php-pyai

# Directory where the FastAPI application resides
# Please replace /home/php-pyai/fastapi with your actual project directory path
WorkingDirectory=/home/php-pyai/fastapi

# The command to start the application
# It uses the Python 3.8 executable from the SCL environment and runs uvicorn.
# We explicitly call the SCL Python executable path.
ExecStart=/opt/rh/rh-python38/root/usr/bin/python -m uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4

# Restarts the service automatically if it fails (e.g., crashes or stops)
Restart=always

# Standard output (STDOUT) and Standard error (STDERR) are logged by systemd
StandardOutput=journal
StandardError=journal

[Install]
# Defines when the service should be started automatically (e.g., during multi-user system boot)
WantedBy=multi-user.target

 

 

2. 시스템 데몬 로딩 & 서비스 실행 예시

sudo systemctl daemon-reload
sudo systemctl reset-failed fastapi.service
sudo systemctl restart fastapi.service
sudo systemctl status fastapi.service

 

LIST