#!/bin/bash # Update Script for PromdataPanel # ------------------------------- set -e # Config APP_DIR="/opt/promdata-panel" SERVICE_NAME="promdatapanel" # 1. Colors for logs GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${BLUE}=== Starting PromdataPanel Update ===${NC}" # Detect if we're in the app directory if [ ! -d ".git" ]; then if [ -d "$APP_DIR/.git" ]; then cd "$APP_DIR" else echo -e "${RED}Error: Not in a git repository or $APP_DIR. Please run this from the app root.${NC}" exit 1 fi fi # 2. Pull latest code from current branch echo -e "${BLUE}Pulling latest code from git...${NC}" git pull # 3. Update dependencies echo -e "${BLUE}Updating npm dependencies...${NC}" npm install --production # 4. Restart service if systemctl is-active --quiet "$SERVICE_NAME"; then echo -e "${BLUE}Restarting systemd service: $SERVICE_NAME...${NC}" sudo systemctl restart "$SERVICE_NAME" echo -e "${GREEN}Update completed and service restarted!${NC}" elif command -v pm2 &> /dev/null && pm2 list | grep -q "$SERVICE_NAME"; then echo -e "${BLUE}Restarting with PM2...${NC}" pm2 restart "$SERVICE_NAME" echo -e "${GREEN}Update completed and PM2 restarted!${NC}" else echo -e "${RED}Warning: Could not detect an active systemd service or PM2 process named '$SERVICE_NAME'.${NC}" echo -e "${RED}Please restart the application manually.${NC}" fi echo -e "${GREEN}=== Update successfully finished ===${NC}"