Files
proxmox/scripts/start-and-configure-all-services.sh
defiQUG b3a8fe4496
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
chore: sync all changes to Gitea
- Config, docs, scripts, and backup manifests
- Submodule refs unchanged (m = modified content in submodules)

Made-with: Cursor
2026-03-02 11:37:34 -08:00

121 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Start and Configure All Services - PostgreSQL, Redis, and verify Node.js
set -uo pipefail
NODE_IP="${PROXMOX_HOST_R630_01}"
log_info() { echo -e "\033[0;32m[INFO]\033[0m $1"; }
log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
log_success() { echo -e "\033[0;32m[✓]\033[0m $1"; }
# Start PostgreSQL and configure database
start_postgresql_and_configure() {
local vmid="$1"
local db_type="$2" # "order" or "dbis"
log_info "Starting PostgreSQL on CT $vmid..."
# Start PostgreSQL
ssh -o ConnectTimeout=15 -o StrictHostKeyChecking=no root@${NODE_IP} "
pct exec $vmid -- systemctl start postgresql@15-main
sleep 5
# Wait for PostgreSQL to be ready
for i in {1..20}; do
pct exec $vmid -- systemctl is-active postgresql@15-main >/dev/null 2>&1 && break
sleep 1
done
if pct exec $vmid -- systemctl is-active postgresql@15-main >/dev/null 2>&1; then
echo 'PostgreSQL is active'
# Configure database
if [ \"$db_type\" = \"order\" ]; then
pct exec $vmid -- su - postgres -c \"
psql << 'SQL_EOF'
CREATE DATABASE order_db;
CREATE USER order_user WITH PASSWORD 'order_password';
GRANT ALL PRIVILEGES ON DATABASE order_db TO order_user;
ALTER DATABASE order_db OWNER TO order_user;
SQL_EOF
\" 2>&1 && echo 'Order DB configured' || echo 'Config failed'
else
pct exec $vmid -- su - postgres -c \"
psql << 'SQL_EOF'
CREATE DATABASE dbis_core;
CREATE USER dbis WITH PASSWORD '8cba649443f97436db43b34ab2c0e75b5cf15611bef9c099cee6fb22cc3d7771';
GRANT ALL PRIVILEGES ON DATABASE dbis_core TO dbis;
ALTER DATABASE dbis_core OWNER TO dbis;
SQL_EOF
\" 2>&1 && echo 'DBIS DB configured' || echo 'Config failed'
fi
else
echo 'PostgreSQL not active'
fi
" && log_success "PostgreSQL configured on CT $vmid" || log_error "Failed to configure PostgreSQL on CT $vmid"
}
# Start Redis
start_redis() {
local vmid="$1"
log_info "Starting Redis on CT $vmid..."
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no root@${NODE_IP} "
pct exec $vmid -- systemctl start redis-server
sleep 3
pct exec $vmid -- systemctl is-active redis-server && echo 'Redis started' || echo 'Redis start failed'
" && log_success "Redis started on CT $vmid" || log_error "Failed to start Redis on CT $vmid"
}
echo "═══════════════════════════════════════════════════════════"
echo "Start and Configure All Services"
echo "═══════════════════════════════════════════════════════════"
echo ""
# Start and configure PostgreSQL
log_info "Starting and configuring PostgreSQL..."
for vmid in 10000 10001; do
start_postgresql_and_configure "$vmid" "order"
sleep 3
done
for vmid in 10100 10101; do
start_postgresql_and_configure "$vmid" "dbis"
sleep 3
done
# Start Redis
log_info "Starting Redis..."
for vmid in 10020 10120; do
start_redis "$vmid"
sleep 2
done
# Verify all services
echo ""
log_info "Service Status:"
echo "PostgreSQL:"
for vmid in 10000 10001 10100 10101; do
status=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct exec $vmid -- systemctl is-active postgresql@15-main 2>&1 || echo 'inactive'")
echo " CT $vmid: $status"
done
echo "Redis:"
for vmid in 10020 10120; do
status=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct exec $vmid -- systemctl is-active redis-server 2>&1 || echo 'inactive'")
echo " CT $vmid: $status"
done
echo "Node.js:"
for vmid in 10030 10040 10050 10060 10070 10080 10090 10091 10092 10130 10150 10151; do
version=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct exec $vmid -- node --version 2>&1 | head -1 || echo 'not installed'")
echo " CT $vmid: $version"
done
echo ""
log_success "All services started and configured!"