Initial commit for deployment

This commit is contained in:
Iyeoluwa Akinrinola
2025-05-09 15:41:16 +01:00
commit ac98999507
54 changed files with 4343 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
#!/bin/bash
# Remote deployment script for the AI service
# Usage: ./remote_deploy.sh [server_ip] [user] [port] [remote_dir]
# Default values
SERVER_IP=${1:-"104.225.217.215"}
SERVER_USER=${2:-"root"}
SERVER_PORT=${3:-"22"}
REMOTE_DIR=${4:-"/root/openwebui"}
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 && \
pip install python-dotenv langchain-text-splitters"
# Stop any existing service
echo "Stopping any existing service..."
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "pkill -f 'uvicorn ai_service.run:app' || true"
# 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
ssh -p $SERVER_PORT $SERVER_USER@$SERVER_IP "ps aux | grep 'uvicorn ai_service.run:app' | grep -v grep"
if [ $? -eq 0 ]; then
echo "Service is running!"
echo "You can access the API at: http://$SERVER_IP:5251"
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!"