add service

This commit is contained in:
2026-04-20 20:07:07 +07:00
parent 9b28cc924a
commit b53bb4c8a8
4 changed files with 136 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
#!/bin/bash
# Script cài đặt LiteRT-LM systemd service cho Linux
echo "========================================"
echo " Cài đặt LiteRT-LM Service"
echo "========================================"
echo
# Lấy thông tin user và đường dẫn hiện tại
CURRENT_USER=$(whoami)
CURRENT_DIR=$(pwd)
PYTHON_PATH=$(which python3)
# Kiểm tra quyền sudo
if [ "$EUID" -ne 0 ]; then
echo "[ERROR] Vui lòng chạy script với sudo:"
echo " sudo bash install_service.sh"
exit 1
fi
# Tạo file config model mặc định nếu chưa có
if [ ! -f "service_config.txt" ]; then
echo "1" > service_config.txt
chown $SUDO_USER:$SUDO_USER service_config.txt
echo "[✓] Đã tạo service_config.txt với model mặc định: 1"
fi
# Tạo file service từ template
echo "[1/4] Tạo file systemd service..."
cat > /tmp/litert-lm.service << EOF
[Unit]
Description=LiteRT-LM Server Service
After=network.target
[Service]
Type=simple
User=$SUDO_USER
WorkingDirectory=$CURRENT_DIR
Environment="PATH=/usr/bin:/usr/local/bin:$HOME/.local/bin"
ExecStart=$PYTHON_PATH $CURRENT_DIR/server.py
StandardInput=file:$CURRENT_DIR/service_config.txt
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Copy file service vào systemd
echo "[2/4] Cài đặt service vào systemd..."
cp /tmp/litert-lm.service /etc/systemd/system/litert-lm.service
chmod 644 /etc/systemd/system/litert-lm.service
# Reload systemd
echo "[3/4] Reload systemd daemon..."
systemctl daemon-reload
# Enable và start service
echo "[4/4] Kích hoạt và khởi động service..."
systemctl enable litert-lm.service
systemctl start litert-lm.service
echo
echo "========================================"
echo " Cài đặt thành công!"
echo "========================================"
echo
echo "Service đã được cài đặt và khởi động."
echo "Server sẽ tự động chạy khi khởi động hệ thống."
echo
echo "Các lệnh quản lý:"
echo " - Xem trạng thái: sudo systemctl status litert-lm"
echo " - Dừng service: sudo systemctl stop litert-lm"
echo " - Khởi động service: sudo systemctl start litert-lm"
echo " - Khởi động lại: sudo systemctl restart litert-lm"
echo " - Xem logs: sudo journalctl -u litert-lm -f"
echo " - Gỡ cài đặt: sudo bash uninstall_service.sh"
echo
echo "Server đang chạy tại: http://localhost:8000"
echo
# Hiển thị trạng thái
systemctl status litert-lm.service --no-pager
+16
View File
@@ -0,0 +1,16 @@
[Unit]
Description=LiteRT-LM Server Service
After=network.target
[Service]
Type=simple
User=your_username
WorkingDirectory=/home/your_username/litert-lm-orangepi
Environment="PATH=/usr/bin:/usr/local/bin"
ExecStart=/usr/bin/python3 /home/your_username/litert-lm-orangepi/server.py
StandardInput=file:/home/your_username/litert-lm-orangepi/service_config.txt
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
+1
View File
@@ -0,0 +1 @@
1
+36
View File
@@ -0,0 +1,36 @@
#!/bin/bash
# Script gỡ cài đặt LiteRT-LM systemd service
echo "========================================"
echo " Gỡ cài đặt LiteRT-LM Service"
echo "========================================"
echo
# Kiểm tra quyền sudo
if [ "$EUID" -ne 0 ]; then
echo "[ERROR] Vui lòng chạy script với sudo:"
echo " sudo bash uninstall_service.sh"
exit 1
fi
# Dừng service
echo "[1/3] Dừng service..."
systemctl stop litert-lm.service
# Disable service
echo "[2/3] Vô hiệu hóa service..."
systemctl disable litert-lm.service
# Xóa file service
echo "[3/3] Xóa file service..."
rm -f /etc/systemd/system/litert-lm.service
# Reload systemd
systemctl daemon-reload
systemctl reset-failed
echo
echo "========================================"
echo " Gỡ cài đặt thành công!"
echo "========================================"
echo