Files
proxmox-script/byparr-lxc-setup.sh
2025-05-24 21:27:26 +08:00

101 lines
3.3 KiB
Bash

#!/bin/bash
# Script to create and configure an LXC container in Proxmox for running Byparr
# Assumes Proxmox is installed and user has sufficient permissions
# Configuration variables
CTID=109 # Container ID
CTNAME="byparr-ct" # Container name
STORAGE="local-lvm" # Storage for the container (adjust as needed)
ROOTFS_SIZE="8" # Root filesystem size in GB
MEMORY=2048 # Memory in MB
CPU_CORES=2 # Number of CPU cores
HOSTNAME="byparr" # Hostname for the container
NETWORK="name=eth0,bridge=vmbr0,ip=dhcp" # Network configuration
TEMPLATE="local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" # Debian 12 template
# Byparr-specific variables
BYPARR_PORT="8191" # Default Byparr port
# Step 1: Create LXC container
echo "Creating LXC container with ID ${CTID}..."
pct create ${CTID} ${TEMPLATE} \
--hostname ${HOSTNAME} \
--storage ${STORAGE} \
--rootfs ${ROOTFS_SIZE} \
--memory ${MEMORY} \
--cores ${CPU_CORES} \
--net0 ${NETWORK} \
--unprivileged 0 \
--features nesting=1,keyctl=1 # Enable nesting for Docker
if [ $? -ne 0 ]; then
echo "Error: Failed to create LXC container. Exiting."
exit 1
fi
# Step 2: Start the container
echo "Starting LXC container ${CTID}..."
pct start ${CTID}
# Step 3: Update container, configure locale, and install dependencies
echo "Updating container and installing dependencies..."
pct exec ${CTID} -- bash -c "
apt-get update && apt-get upgrade -y &&
apt-get install -y curl ca-certificates gnupg locales &&
echo 'en_US.UTF-8 UTF-8' > /etc/locale.gen &&
locale-gen en_US.UTF-8 &&
update-locale LANG=en_US.UTF-8
"
# Step 4: Install Docker inside the LXC container
echo "Installing Docker..."
pct exec ${CTID} -- bash -c "
curl -fsSL https://get.docker.com -o get-docker.sh &&
sh get-docker.sh &&
rm get-docker.sh
"
# Step 5: Create directory for Byparr and set up Docker Compose configuration
echo "Setting up Byparr Docker Compose configuration..."
pct exec ${CTID} -- bash -c "
mkdir -p /root/byparr &&
cd /root/byparr &&
cat <<EOF > docker-compose.yml
version: '3.8'
services:
byparr:
image: ghcr.io/thephaseless/byparr:latest
container_name: byparr
restart: unless-stopped
shm_size: 2gb
environment:
- PUID=1000
- PGID=1000
volumes:
- ./screenshots:/app/screenshots
ports:
- \"${BYPARR_PORT}:8191\"
EOF
"
# Step 6: Pull and run Byparr using Docker Compose
echo "Pulling and starting Byparr container..."
pct exec ${CTID} -- bash -c "
cd /root/byparr &&
docker compose pull &&
docker compose up -d
"
# Step 7: Verify Byparr is running
echo "Verifying Byparr service..."
sleep 5 # Wait for the service to start
pct exec ${CTID} -- bash -c "
curl -s http://localhost:${BYPARR_PORT}/health | grep -q 'OK' && echo 'Byparr is running successfully!' || echo 'Error: Byparr failed to start.'
"
# Step 8: Display access information
IP_ADDRESS=$(pct exec ${CTID} -- bash -c "ip addr show eth0 | grep 'inet ' | awk '{print \$2}' | cut -d'/' -f1")
echo "Setup complete! Byparr is accessible at http://${IP_ADDRESS}:${BYPARR_PORT}"
echo "API documentation is available at http://${IP_ADDRESS}:${BYPARR_PORT}/docs"
echo "To stop the container, run: pct stop ${CTID}"
echo "To start the container later, run: pct start ${CTID} && pct exec ${CTID} -- bash -c 'cd /root/byparr && docker compose up -d'"