Initial commit: Inventory Barcode System
This commit is contained in:
43
scripts/deploy-from-git.sh
Normal file
43
scripts/deploy-from-git.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/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!"
|
||||
Reference in New Issue
Block a user