243 lines
6.1 KiB
Bash
Executable File
243 lines
6.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# IPMI Controller - Production Deployment Script
|
|
# Run this on the production server to set up auto-start and persistence
|
|
|
|
set -e
|
|
|
|
INSTALL_DIR="/opt/ipmi-controller"
|
|
DATA_DIR="$INSTALL_DIR/data"
|
|
SERVICE_NAME="ipmi-controller"
|
|
USER="devmatrix"
|
|
|
|
echo "🌡️ IPMI Controller - Production Deployment"
|
|
echo "============================================="
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "❌ Please run as root: sudo ./deploy-prod.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Get the source directory
|
|
SOURCE_DIR="${1:-$(pwd)}"
|
|
if [ ! -f "$SOURCE_DIR/web_server.py" ]; then
|
|
echo "❌ Cannot find web_server.py in $SOURCE_DIR"
|
|
echo "Usage: sudo ./deploy-prod.sh [source-directory]"
|
|
exit 1
|
|
fi
|
|
|
|
echo "📁 Source: $SOURCE_DIR"
|
|
echo "📁 Install: $INSTALL_DIR"
|
|
echo ""
|
|
|
|
# Create directories
|
|
echo "📂 Creating directories..."
|
|
mkdir -p "$INSTALL_DIR"
|
|
mkdir -p "$DATA_DIR"
|
|
mkdir -p /var/log/ipmi-controller
|
|
|
|
# Copy application files
|
|
echo "📋 Copying application files..."
|
|
cp "$SOURCE_DIR/web_server.py" "$INSTALL_DIR/"
|
|
cp "$SOURCE_DIR/fan_controller.py" "$INSTALL_DIR/"
|
|
cp "$SOURCE_DIR/requirements.txt" "$INSTALL_DIR/"
|
|
|
|
# Install dependencies
|
|
echo "🐍 Installing Python dependencies..."
|
|
pip3 install -q -r "$SOURCE_DIR/requirements.txt" || pip install -q -r "$SOURCE_DIR/requirements.txt"
|
|
|
|
# Install ipmitool if not present
|
|
if ! command -v ipmitool &> /dev/null; then
|
|
echo "📦 Installing ipmitool..."
|
|
apt-get update -qq
|
|
apt-get install -y -qq ipmitool
|
|
fi
|
|
|
|
# Preserve existing config if it exists
|
|
if [ -f "$DATA_DIR/config.json" ]; then
|
|
echo "💾 Preserving existing configuration..."
|
|
cp "$DATA_DIR/config.json" "$DATA_DIR/config.json.backup.$(date +%Y%m%d%H%M%S)"
|
|
else
|
|
echo "⚙️ Creating default configuration..."
|
|
cat > "$DATA_DIR/config.json" << 'EOF'
|
|
{
|
|
"ipmi_host": "",
|
|
"ipmi_username": "",
|
|
"ipmi_password": "",
|
|
"ipmi_port": 623,
|
|
"http_sensor_enabled": false,
|
|
"http_sensor_url": "",
|
|
"http_sensor_timeout": 10,
|
|
"enabled": false,
|
|
"poll_interval": 10,
|
|
"min_speed": 10,
|
|
"max_speed": 100,
|
|
"panic_temp": 85,
|
|
"panic_speed": 100,
|
|
"panic_on_no_data": true,
|
|
"no_data_timeout": 60,
|
|
"primary_sensor": "cpu",
|
|
"sensor_preference": "auto",
|
|
"fans": {},
|
|
"fan_groups": {},
|
|
"fan_curves": {
|
|
"Balanced": {
|
|
"points": [
|
|
{"temp": 30, "speed": 10},
|
|
{"temp": 35, "speed": 12},
|
|
{"temp": 40, "speed": 15},
|
|
{"temp": 45, "speed": 20},
|
|
{"temp": 50, "speed": 30},
|
|
{"temp": 55, "speed": 40},
|
|
{"temp": 60, "speed": 55},
|
|
{"temp": 65, "speed": 70},
|
|
{"temp": 70, "speed": 85},
|
|
{"temp": 75, "speed": 95},
|
|
{"temp": 80, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
},
|
|
"Silent": {
|
|
"points": [
|
|
{"temp": 30, "speed": 5},
|
|
{"temp": 40, "speed": 10},
|
|
{"temp": 50, "speed": 15},
|
|
{"temp": 55, "speed": 25},
|
|
{"temp": 60, "speed": 35},
|
|
{"temp": 65, "speed": 50},
|
|
{"temp": 70, "speed": 70},
|
|
{"temp": 75, "speed": 85},
|
|
{"temp": 80, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
},
|
|
"Performance": {
|
|
"points": [
|
|
{"temp": 30, "speed": 20},
|
|
{"temp": 35, "speed": 25},
|
|
{"temp": 40, "speed": 35},
|
|
{"temp": 45, "speed": 45},
|
|
{"temp": 50, "speed": 55},
|
|
{"temp": 55, "speed": 70},
|
|
{"temp": 60, "speed": 85},
|
|
{"temp": 65, "speed": 95},
|
|
{"temp": 70, "speed": 100}
|
|
],
|
|
"sensor_source": "cpu",
|
|
"applies_to": "all"
|
|
}
|
|
},
|
|
"active_curve": "Balanced",
|
|
"theme": "dark"
|
|
}
|
|
EOF
|
|
fi
|
|
|
|
# Create users file if not exists
|
|
if [ ! -f "$DATA_DIR/users.json" ]; then
|
|
echo '{"users": {}}' > "$DATA_DIR/users.json"
|
|
fi
|
|
|
|
# Set ownership
|
|
chown -R "$USER:$USER" "$INSTALL_DIR"
|
|
chown -R "$USER:$USER" /var/log/ipmi-controller
|
|
|
|
# Create systemd service
|
|
echo "🔧 Creating systemd service..."
|
|
cat > "/etc/systemd/system/$SERVICE_NAME.service" << EOF
|
|
[Unit]
|
|
Description=IPMI Controller - Fan Control for Dell Servers
|
|
After=network.target
|
|
Wants=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=$USER
|
|
Group=$USER
|
|
WorkingDirectory=$INSTALL_DIR
|
|
Environment="PYTHONUNBUFFERED=1"
|
|
Environment="DATA_DIR=$DATA_DIR"
|
|
Environment="LOG_DIR=/var/log/ipmi-controller"
|
|
ExecStart=/usr/bin/python3 $INSTALL_DIR/web_server.py
|
|
ExecStop=/bin/kill -TERM \$MAINPID
|
|
ExecReload=/bin/kill -HUP \$MAINPID
|
|
|
|
# Restart policy
|
|
Restart=always
|
|
RestartSec=10
|
|
StartLimitInterval=60s
|
|
StartLimitBurst=3
|
|
|
|
# Logging
|
|
StandardOutput=append:/var/log/ipmi-controller/server.log
|
|
StandardError=append:/var/log/ipmi-controller/error.log
|
|
|
|
# Security
|
|
NoNewPrivileges=false
|
|
ProtectSystem=no
|
|
ProtectHome=no
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Create logrotate config
|
|
echo "📝 Creating logrotate config..."
|
|
cat > "/etc/logrotate.d/ipmi-controller" << EOF
|
|
/var/log/ipmi-controller/*.log {
|
|
daily
|
|
rotate 14
|
|
compress
|
|
delaycompress
|
|
missingok
|
|
notifempty
|
|
create 644 $USER $USER
|
|
sharedscripts
|
|
postrotate
|
|
systemctl reload ipmi-controller
|
|
endscript
|
|
}
|
|
EOF
|
|
|
|
# Reload systemd
|
|
echo "🔄 Reloading systemd..."
|
|
systemctl daemon-reload
|
|
|
|
# Enable service
|
|
echo "✅ Enabling service to start on boot..."
|
|
systemctl enable "$SERVICE_NAME"
|
|
|
|
echo ""
|
|
echo "🚀 Starting IPMI Controller..."
|
|
systemctl start "$SERVICE_NAME"
|
|
|
|
sleep 2
|
|
|
|
# Check status
|
|
if systemctl is-active --quiet "$SERVICE_NAME"; then
|
|
echo ""
|
|
echo "✅ IPMI Controller is running!"
|
|
echo ""
|
|
echo "🌐 Access: http://$(hostname -I | awk '{print $1}'):8000"
|
|
echo ""
|
|
echo "📋 Management Commands:"
|
|
echo " Status: sudo systemctl status $SERVICE_NAME"
|
|
echo " Logs: sudo journalctl -u $SERVICE_NAME -f"
|
|
echo " Restart: sudo systemctl restart $SERVICE_NAME"
|
|
echo " Stop: sudo systemctl stop $SERVICE_NAME"
|
|
echo ""
|
|
echo "💾 Settings: $DATA_DIR/config.json"
|
|
echo "📜 Logs: /var/log/ipmi-controller/"
|
|
echo ""
|
|
echo "✅ Production deployment complete!"
|
|
echo " Service will auto-start on boot."
|
|
else
|
|
echo ""
|
|
echo "⚠️ Service failed to start. Check logs:"
|
|
echo " sudo journalctl -u $SERVICE_NAME -f"
|
|
exit 1
|
|
fi
|