VigilanzaTurni/deploy/setup-server.sh
marco370 5a51a65218 Add deployment guide and scripts for automated server setup and deployment
Adds a comprehensive DEPLOYMENT.md guide, a setup-server.sh script for AlmaLinux 9 to install Node.js, PostgreSQL, Nginx, and PM2, a deploy.sh script for CI/CD deployment, an nginx.conf for server configuration, and a push-to-gitlab.sh helper script for Replit integration.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 99f0fce6-9386-489a-9632-1d81223cab44
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/99f0fce6-9386-489a-9632-1d81223cab44/H8Wilyj
2025-10-16 07:12:27 +00:00

109 lines
3.1 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "================================================"
echo "Setup VigilanzaTurni su AlmaLinux 9"
echo "================================================"
# Colori per output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Funzione di log
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Verifica root
if [ "$EUID" -ne 0 ]; then
log_error "Esegui questo script come root: sudo bash setup-server.sh"
exit 1
fi
log_info "Aggiornamento sistema..."
dnf update -y
# =================== NODE.JS 20 ===================
log_info "Installazione Node.js 20 LTS..."
dnf module reset nodejs -y
dnf module enable nodejs:20 -y
dnf install nodejs -y
node --version
npm --version
# =================== POSTGRESQL 15 ===================
log_info "Installazione PostgreSQL 15..."
dnf install -y postgresql15-server postgresql15-contrib
postgresql-setup --initdb
systemctl enable postgresql
systemctl start postgresql
# Creazione database e utente
log_info "Configurazione database..."
sudo -u postgres psql << EOF
CREATE DATABASE vigilanza_turni;
CREATE USER vigilanza_user WITH ENCRYPTED PASSWORD 'ChangeMe_ProductionPassword123!';
GRANT ALL PRIVILEGES ON DATABASE vigilanza_turni TO vigilanza_user;
\c vigilanza_turni
GRANT ALL ON SCHEMA public TO vigilanza_user;
EOF
# Configurazione PostgreSQL per connessioni locali
log_info "Configurazione autenticazione PostgreSQL..."
PG_HBA="/var/lib/pgsql/data/pg_hba.conf"
sed -i 's/ident$/md5/' $PG_HBA
systemctl restart postgresql
# =================== PM2 (Process Manager) ===================
log_info "Installazione PM2..."
npm install -g pm2
pm2 startup systemd -u root --hp /root
# =================== NGINX ===================
log_info "Installazione Nginx..."
dnf install -y nginx
systemctl enable nginx
# =================== GIT ===================
log_info "Installazione Git..."
dnf install -y git
# =================== DIRECTORY APPLICAZIONE ===================
log_info "Creazione directory applicazione..."
mkdir -p /var/www/vigilanza-turni
chown -R root:root /var/www/vigilanza-turni
# =================== FIREWALL ===================
log_info "Configurazione Firewall..."
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
# =================== SSL CERTIFICATE (Let's Encrypt) ===================
log_info "Installazione Certbot per SSL..."
dnf install -y certbot python3-certbot-nginx
log_info ""
log_info "================================================"
log_info "Setup completato con successo!"
log_info "================================================"
log_info ""
log_warn "PROSSIMI PASSI:"
echo "1. Configura il DNS per puntare questo server"
echo "2. Modifica la password PostgreSQL in /var/www/vigilanza-turni/.env"
echo "3. Ottieni certificato SSL: sudo certbot --nginx -d tuodominio.it"
echo "4. Esegui il primo deployment con GitLab CI/CD"
echo ""
log_info "DATABASE_URL per .env:"
echo "postgresql://vigilanza_user:ChangeMe_ProductionPassword123!@localhost:5432/vigilanza_turni"