Files
proxmox/scripts/start-services-manually.sh

82 lines
2.8 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# Start Services Manually - Bypass systemd for unprivileged containers
set -uo pipefail
NODE_IP="${PROXMOX_HOST_R630_01}"
log_info() { echo -e "\033[0;32m[INFO]\033[0m $1"; }
log_success() { echo -e "\033[0;32m[✓]\033[0m $1"; }
log_error() { echo -e "\033[0;31m[ERROR]\033[0m $1"; }
start_postgresql_manual() {
local vmid="$1"
log_info "Starting PostgreSQL manually on CT $vmid..."
ssh -o ConnectTimeout=15 -o StrictHostKeyChecking=no root@${NODE_IP} "
pct exec $vmid -- bash -c '
# Start PostgreSQL manually
su - postgres -c \"pg_ctl -D /var/lib/postgresql/15/main -l /tmp/postgresql.log start\" 2>&1
sleep 3
# Verify it's running
su - postgres -c \"psql -c \\\"SELECT version();\\\"\" 2>&1 | head -1 && echo \"PostgreSQL running\" || echo \"PostgreSQL failed\"
'
" && log_success "PostgreSQL started on CT $vmid" || log_error "Failed on CT $vmid"
}
start_redis_manual() {
local vmid="$1"
log_info "Starting Redis manually on CT $vmid..."
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no root@${NODE_IP} "
pct exec $vmid -- bash -c '
# Start Redis manually
redis-server /etc/redis/redis.conf --daemonize yes 2>&1
sleep 2
# Verify it's running
redis-cli ping 2>&1 | head -1 && echo \"Redis running\" || echo \"Redis failed\"
'
" && log_success "Redis started on CT $vmid" || log_error "Failed on CT $vmid"
}
echo "═══════════════════════════════════════════════════════════"
echo "Start Services Manually"
echo "═══════════════════════════════════════════════════════════"
echo ""
# Start PostgreSQL
log_info "Starting PostgreSQL manually..."
for vmid in 10000 10001 10100 10101; do
start_postgresql_manual "$vmid"
sleep 2
done
# Start Redis
log_info "Starting Redis manually..."
for vmid in 10020 10120; do
start_redis_manual "$vmid"
sleep 2
done
# Verify services
echo ""
log_info "Service Status:"
echo "PostgreSQL:"
for vmid in 10000 10001 10100 10101; do
result=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct exec $vmid -- bash -c 'su - postgres -c \"psql -c \\\"SELECT 1;\\\"\" 2>&1 | head -1'")
echo " CT $vmid: $result"
done
echo "Redis:"
for vmid in 10020 10120; do
result=$(ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no root@${NODE_IP} \
"pct exec $vmid -- bash -c 'redis-cli ping 2>&1 | head -1'")
echo " CT $vmid: $result"
done
echo ""
log_success "Manual service startup complete!"