Files
inventory-barcode-system/scripts/deploy-from-git.sh

43 lines
1.0 KiB
Bash

#!/bin/bash
# Automated deployment script for Gitea webhook
# This script pulls the latest code and restarts the application
set -e
# Configuration
REPO_DIR="/path/to/your/inventory-barcode-system"
LOG_FILE="/var/log/inventory-deploy.log"
SERVICE_NAME="inventory-barcode-system"
# Logging function
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE"
}
log "Starting deployment..."
# Navigate to repository directory
cd "$REPO_DIR"
# Pull latest changes
log "Pulling latest changes from Gitea..."
git pull origin main
# Install/update dependencies
log "Installing dependencies..."
npm ci --only=production
# Restart the application
log "Restarting application..."
if command -v pm2 &> /dev/null; then
pm2 restart "$SERVICE_NAME" || pm2 start server.js --name "$SERVICE_NAME"
elif command -v systemctl &> /dev/null; then
sudo systemctl restart "$SERVICE_NAME"
else
# Kill existing process and start new one
pkill -f "node server.js" || true
nohup npm start > /dev/null 2>&1 &
fi
log "Deployment completed successfully!"