Add PBS platform detection and expanded .env configuration

Detects PVE vs PBS at startup, installs platform-specific packages
(iperf3/fio for PVE, zfsutils-linux for PBS), and generates .env
with all hwmonDaemon config options pre-populated based on platform.

Fixes: LotusGuild/hwmonDaemon#5

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-10 13:20:04 -05:00
parent 2b8d3a7e38
commit d5d6038a53

View File

@@ -3,6 +3,21 @@ set -e
echo "Starting Proxmox fresh installation script..." echo "Starting Proxmox fresh installation script..."
# =============================================================================
# Platform Detection
# =============================================================================
PLATFORM="unknown"
if command -v pveversion &>/dev/null; then
PLATFORM="pve"
echo "Detected platform: Proxmox VE ($(pveversion 2>/dev/null || echo 'version unknown'))"
elif command -v proxmox-backup-manager &>/dev/null; then
PLATFORM="pbs"
echo "Detected platform: Proxmox Backup Server"
else
echo "WARNING: Could not detect Proxmox platform (PVE or PBS)"
echo "Proceeding with common package installation..."
fi
# Cleanup function for failed installations # Cleanup function for failed installations
cleanup() { cleanup() {
echo "Cleaning up on error..." echo "Cleaning up on error..."
@@ -26,7 +41,20 @@ trap cleanup ERR
# Install dependencies # Install dependencies
echo "Installing required packages..." echo "Installing required packages..."
apt-get update apt-get update
apt-get install -y python3-pip smartmontools iperf3 python3-psutil python3-requests lm-sensors fastfetch rsync fio jq sysstat
# Common packages for all platforms
COMMON_PKGS="python3-pip smartmontools python3-psutil python3-requests lm-sensors fastfetch rsync jq sysstat"
if [[ "$PLATFORM" == "pve" ]]; then
echo "Installing PVE-specific packages..."
apt-get install -y $COMMON_PKGS iperf3 fio nvme-cli
elif [[ "$PLATFORM" == "pbs" ]]; then
echo "Installing PBS-specific packages..."
apt-get install -y $COMMON_PKGS zfsutils-linux nvme-cli
else
echo "Installing common packages..."
apt-get install -y $COMMON_PKGS nvme-cli
fi
# Install Node Exporter # Install Node Exporter
echo "Installing Prometheus Node Exporter..." echo "Installing Prometheus Node Exporter..."
@@ -137,27 +165,82 @@ echo " /etc/hwmonDaemon/.env"
echo "" echo ""
read -p "Enter API key (or press Enter to skip): " API_KEY read -p "Enter API key (or press Enter to skip): " API_KEY
# Determine platform-specific defaults
if [[ "$PLATFORM" == "pbs" ]]; then
PBS_DEFAULT="true"
CEPH_DEFAULT="false"
else
PBS_DEFAULT="false"
CEPH_DEFAULT="true"
fi
if [[ -n "$API_KEY" ]]; then if [[ -n "$API_KEY" ]]; then
# Create .env file with API key # Create .env file with API key and all config options
cat > /etc/hwmonDaemon/.env << EOF cat > /etc/hwmonDaemon/.env << EOF
# hwmonDaemon Configuration # hwmonDaemon Configuration
# Auto-generated by freshStart.sh on $(date) # Auto-generated by freshStart.sh on $(date)
# Platform: ${PLATFORM}
# Ticket API Configuration # Ticket API Configuration
TICKET_API_KEY=$API_KEY TICKET_API_KEY=$API_KEY
TICKET_API_URL=http://10.10.10.45/create_ticket_api.php TICKET_API_URL=http://10.10.10.45/create_ticket_api.php
# Cluster Identification
CLUSTER_NAME=proxmox-cluster
# Ceph Monitoring (PVE nodes)
CEPH_ENABLED=${CEPH_DEFAULT}
#CEPH_TICKET_NODE=
#CEPH_USAGE_WARNING=70
#CEPH_USAGE_CRITICAL=85
# PBS Monitoring (Proxmox Backup Server)
PBS_ENABLED=${PBS_DEFAULT}
#PBS_ZFS_WARNING=80
#PBS_ZFS_CRITICAL=90
# Prometheus Metrics
PROMETHEUS_ENABLED=false
#PROMETHEUS_PORT=9101
# Health Check Endpoint
HEALTH_SERVER_ENABLED=false
#HEALTH_SERVER_PORT=9102
EOF EOF
chmod 600 /etc/hwmonDaemon/.env chmod 600 /etc/hwmonDaemon/.env
echo "✓ API key configured in /etc/hwmonDaemon/.env" echo "✓ API key configured in /etc/hwmonDaemon/.env"
else else
# Create template .env file # Create template .env file with all config options
cat > /etc/hwmonDaemon/.env << 'EOF' cat > /etc/hwmonDaemon/.env << EOF
# hwmonDaemon Configuration # hwmonDaemon Configuration
# Edit this file to add your API key # Edit this file to add your API key
# Platform: ${PLATFORM}
# Ticket API Configuration # Ticket API Configuration
TICKET_API_KEY=your_api_key_here TICKET_API_KEY=your_api_key_here
TICKET_API_URL=http://10.10.10.45/create_ticket_api.php TICKET_API_URL=http://10.10.10.45/create_ticket_api.php
# Cluster Identification
CLUSTER_NAME=proxmox-cluster
# Ceph Monitoring (PVE nodes)
CEPH_ENABLED=${CEPH_DEFAULT}
#CEPH_TICKET_NODE=
#CEPH_USAGE_WARNING=70
#CEPH_USAGE_CRITICAL=85
# PBS Monitoring (Proxmox Backup Server)
PBS_ENABLED=${PBS_DEFAULT}
#PBS_ZFS_WARNING=80
#PBS_ZFS_CRITICAL=90
# Prometheus Metrics
PROMETHEUS_ENABLED=false
#PROMETHEUS_PORT=9101
# Health Check Endpoint
HEALTH_SERVER_ENABLED=false
#HEALTH_SERVER_PORT=9102
EOF EOF
chmod 600 /etc/hwmonDaemon/.env chmod 600 /etc/hwmonDaemon/.env
echo "⚠️ WARNING: API key not configured!" echo "⚠️ WARNING: API key not configured!"
@@ -199,9 +282,11 @@ trap - ERR
echo "✓ Installation complete! All services are running correctly." echo "✓ Installation complete! All services are running correctly."
echo "" echo ""
echo "Platform: ${PLATFORM^^}"
echo ""
echo "Services installed:" echo "Services installed:"
echo " - Node Exporter: http://$(hostname -I | awk '{print $1}'):9100/metrics" echo " - Node Exporter: http://$(hostname -I | awk '{print $1}'):9100/metrics"
echo " - hwmon daemon: Monitoring system health every 15 minutes" echo " - hwmon daemon: Monitoring system health hourly"
echo "" echo ""
echo "Configuration files:" echo "Configuration files:"
echo " - hwmon config: /etc/hwmonDaemon/.env" echo " - hwmon config: /etc/hwmonDaemon/.env"
@@ -211,6 +296,17 @@ echo " - Node Exporter: journalctl -u node_exporter"
echo " - hwmon: journalctl -u hwmon.service" echo " - hwmon: journalctl -u hwmon.service"
echo " - hwmon logs: /var/log/hwmonDaemon/" echo " - hwmon logs: /var/log/hwmonDaemon/"
echo "" echo ""
if [[ "$PLATFORM" == "pbs" ]]; then
echo "PBS-specific monitoring enabled:"
echo " - ZFS pool health and usage monitoring"
echo " - Failed backup/GC/sync task detection"
echo ""
elif [[ "$PLATFORM" == "pve" ]]; then
echo "PVE-specific monitoring enabled:"
echo " - Ceph cluster health monitoring"
echo " - LXC container storage monitoring"
echo ""
fi
if [[ ! -s /etc/hwmonDaemon/.env ]] || grep -q "your_api_key_here" /etc/hwmonDaemon/.env 2>/dev/null; then if [[ ! -s /etc/hwmonDaemon/.env ]] || grep -q "your_api_key_here" /etc/hwmonDaemon/.env 2>/dev/null; then
echo "⚠️ REMINDER: Configure your API key in /etc/hwmonDaemon/.env" echo "⚠️ REMINDER: Configure your API key in /etc/hwmonDaemon/.env"
fi fi