Files

75 lines
2.8 KiB
Bash
Raw Permalink Normal View History

2025-05-09 15:41:16 +01:00
#!/bin/bash
# Remote deployment script for the AI service
# Usage: ./remote_deploy.sh [server_ip] [user] [port] [remote_dir]
# Default values
2025-05-09 16:47:30 +01:00
SERVER_IP=${1:-"104.225.217.215"} # IP address of the server where OpenWebUI is installed
SERVER_USER=${2:-"root"} # SSH username for the server
SERVER_PORT=${3:-"22"} # SSH port for the server
REMOTE_DIR=${4:-"/root/openwebui"} # Directory where OpenWebUI is installed
2025-05-09 15:41:16 +01:00
LOCAL_DIR="."
echo "Deploying to server: $SERVER_IP"
echo "Remote directory: $REMOTE_DIR"
# Check if the server is reachable
echo "Checking if server is reachable..."
ssh -q -o BatchMode=yes -o ConnectTimeout=5 -p $SERVER_PORT $SERVER_USER@$SERVER_IP exit
if [ $? -ne 0 ]; then
echo "Error: Cannot connect to server $SERVER_IP"
exit 1
fi
# Create a subdirectory for our AI service in the OpenWebUI directory
echo "Creating AI service directory in OpenWebUI..."
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "mkdir -p $REMOTE_DIR/ai_service_app"
# Sync files to the server
echo "Syncing files to server..."
rsync -avz -e "ssh -p $SERVER_PORT" --exclude 'venv' --exclude '__pycache__' --exclude '*.pyc' --exclude '.git' \
$LOCAL_DIR/ $SERVER_USER@$SERVER_IP:$REMOTE_DIR/ai_service_app/
# Install dependencies on the server
echo "Installing dependencies on the server..."
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR/ai_service_app && \
python3 -m venv venv || true && \
source venv/bin/activate && \
pip install --upgrade pip && \
pip install -r requirements.txt"
2025-05-09 15:41:16 +01:00
# Stop any existing service
echo "Stopping any existing service..."
2025-05-09 16:47:30 +01:00
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "pkill -f 'uvicorn ai_service.api:app' || true"
# Set up environment file if it doesn't exist
echo "Setting up environment file..."
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR/ai_service_app && \
if [ ! -f ai_service/.env ]; then \
cp ai_service/.env.example ai_service/.env; \
echo 'Created .env file from .env.example'; \
else \
echo '.env file already exists'; \
fi"
2025-05-09 15:41:16 +01:00
# Start the service
echo "Starting the service..."
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "cd $REMOTE_DIR/ai_service_app && \
source venv/bin/activate && \
bash ai_service/deploy.sh"
# Check if the service is running
echo "Checking if the service is running..."
sleep 5
2025-05-09 16:47:30 +01:00
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "ps aux | grep 'uvicorn ai_service.api:app' | grep -v grep"
2025-05-09 15:41:16 +01:00
if [ $? -eq 0 ]; then
echo "Service is running!"
2025-05-09 20:00:26 +01:00
echo "You can access the API at: http://$SERVER_IP:5252"
2025-05-09 15:41:16 +01:00
echo "Check logs with: ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP 'tail -f $REMOTE_DIR/ai_service_app/logs/ai_service.log'"
else
echo "Error: Service failed to start. Check logs on the server."
exit 1
fi
echo "Deployment completed successfully!"