Added pi optimizations
This commit is contained in:
148
setup-pi.sh
Normal file
148
setup-pi.sh
Normal file
@@ -0,0 +1,148 @@
|
||||
#!/bin/bash
|
||||
# Raspberry Pi Optimized Setup Script for Docker Dashboard
|
||||
|
||||
set -e
|
||||
|
||||
echo "🍓 Setting up Docker Dashboard for Raspberry Pi..."
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Detect Raspberry Pi
|
||||
if [[ -f /proc/device-tree/model ]]; then
|
||||
MODEL=$(tr -d '\0' < /proc/device-tree/model)
|
||||
echo -e "${GREEN}Detected: $MODEL${NC}"
|
||||
elif [[ -f /proc/cpuinfo ]] && grep -q "Raspberry Pi" /proc/cpuinfo; then
|
||||
echo -e "${GREEN}Detected: Raspberry Pi${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Warning: Not running on Raspberry Pi, continuing anyway...${NC}"
|
||||
fi
|
||||
|
||||
# Update system packages
|
||||
echo -e "${YELLOW}Updating system packages...${NC}"
|
||||
sudo apt update && sudo apt upgrade -y
|
||||
|
||||
# Install Python3 and pip if not present
|
||||
echo -e "${YELLOW}Installing Python3 and pip...${NC}"
|
||||
sudo apt install -y python3 python3-pip python3-venv curl wget
|
||||
|
||||
# Install Docker if not present
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo -e "${YELLOW}Installing Docker...${NC}"
|
||||
curl -fsSL https://get.docker.com -o get-docker.sh
|
||||
sudo sh get-docker.sh
|
||||
sudo usermod -aG docker $USER
|
||||
rm get-docker.sh
|
||||
else
|
||||
echo -e "${GREEN}Docker already installed${NC}"
|
||||
fi
|
||||
|
||||
# Create virtual environment
|
||||
echo -e "${YELLOW}Creating Python virtual environment...${NC}"
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
|
||||
# Install dependencies optimized for Pi
|
||||
echo -e "${YELLOW}Installing Python dependencies...${NC}"
|
||||
pip install --upgrade pip
|
||||
|
||||
# Install packages with Pi optimizations
|
||||
pip install flask==2.3.3
|
||||
pip install flask-cors==4.0.0
|
||||
pip install docker==6.1.3
|
||||
pip install psutil==5.9.5
|
||||
pip install requests==2.31.0
|
||||
pip install python-dotenv==1.0.0
|
||||
|
||||
# Create .env file optimized for Pi
|
||||
echo -e "${YELLOW}Creating Pi-optimized configuration...${NC}"
|
||||
cat > .env << EOF
|
||||
# Raspberry Pi Optimized Configuration
|
||||
PORT=8080
|
||||
HOST=0.0.0.0
|
||||
DEBUG=false
|
||||
REFRESH_INTERVAL=60
|
||||
PI_OPTIMIZATIONS=true
|
||||
|
||||
# Optional: Portainer integration
|
||||
# PORTAINER_URL=http://localhost:9000
|
||||
# PORTAINER_USERNAME=admin
|
||||
# PORTAINER_PASSWORD=yourpassword
|
||||
|
||||
# Docker socket path (Pi specific)
|
||||
DOCKER_HOST=unix:///var/run/docker.sock
|
||||
EOF
|
||||
|
||||
# Initialize database
|
||||
echo -e "${YELLOW}Initializing database...${NC}"
|
||||
python3 -c "
|
||||
from database import db
|
||||
db.init_database()
|
||||
print('✅ Database initialized successfully')
|
||||
"
|
||||
|
||||
# Create systemd service for auto-start
|
||||
echo -e "${YELLOW}Creating systemd service...${NC}"
|
||||
sudo tee /etc/systemd/system/docker-dashboard.service > /dev/null << EOF
|
||||
[Unit]
|
||||
Description=Docker Dashboard for Raspberry Pi
|
||||
After=network.target docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
WorkingDirectory=$(pwd)
|
||||
Environment=PATH=$(pwd)/venv/bin
|
||||
ExecStart=$(pwd)/venv/bin/python3 api.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Set permissions
|
||||
sudo chmod 644 /etc/systemd/system/docker-dashboard.service
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p logs
|
||||
|
||||
# Create simple start/stop scripts
|
||||
cat > start-pi.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Starting Docker Dashboard on Raspberry Pi..."
|
||||
sudo systemctl start docker-dashboard
|
||||
sudo systemctl status docker-dashboard --no-pager -l
|
||||
EOF
|
||||
|
||||
cat > stop-pi.sh << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "Stopping Docker Dashboard..."
|
||||
sudo systemctl stop docker-dashboard
|
||||
sudo systemctl status docker-dashboard --no-pager -l
|
||||
EOF
|
||||
|
||||
chmod +x start-pi.sh stop-pi.sh
|
||||
|
||||
# Enable service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable docker-dashboard
|
||||
|
||||
echo -e "${GREEN}✅ Setup complete!${NC}"
|
||||
echo ""
|
||||
echo "Usage:"
|
||||
echo " ./start-pi.sh - Start the dashboard"
|
||||
echo " ./stop-pi.sh - Stop the dashboard"
|
||||
echo " ./setup-pi.sh - Re-run this setup"
|
||||
echo ""
|
||||
echo "Access the dashboard at: http://$(hostname -I | awk '{print $1}'):8080"
|
||||
echo ""
|
||||
echo -e "${YELLOW}To start immediately:${NC}"
|
||||
echo " sudo systemctl start docker-dashboard"
|
||||
echo ""
|
||||
echo -e "${YELLOW}To view logs:${NC}"
|
||||
echo " sudo journalctl -u docker-dashboard -f"
|
||||
Reference in New Issue
Block a user