124 lines
3.6 KiB
Bash
124 lines
3.6 KiB
Bash
#!/bin/bash
|
|
# Alternative script to fix cgroup configuration using systemd approach
|
|
|
|
echo "🔧 Fixing cgroup configuration using systemd approach..."
|
|
|
|
# Check if running as root
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
echo "❌ This script must be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
# Update package lists
|
|
echo "📦 Updating package lists..."
|
|
apk update
|
|
|
|
# Install necessary packages
|
|
echo "📦 Installing necessary packages..."
|
|
apk add systemd openrc
|
|
|
|
# Create systemd cgroup configuration
|
|
echo "🔧 Creating systemd cgroup configuration..."
|
|
mkdir -p /etc/systemd
|
|
cat > /etc/systemd/system.conf << 'EOF'
|
|
[Manager]
|
|
DefaultControllers=cpu cpuacct memory devices freezer net_cls blkio cpuset perf_event pids
|
|
EOF
|
|
|
|
# Create systemd cgroup mount configuration
|
|
echo "🔧 Creating systemd cgroup mount configuration..."
|
|
mkdir -p /etc/systemd/system
|
|
cat > /etc/systemd/system/sys-fs-cgroup.mount << 'EOF'
|
|
[Unit]
|
|
Description=Control Group Hierarchy
|
|
DefaultDependencies=no
|
|
Before=sysinit.target
|
|
ConditionPathExists=/sys/fs/cgroup
|
|
|
|
[Mount]
|
|
What=cgroup
|
|
Where=/sys/fs/cgroup
|
|
Type=cgroup
|
|
Options=nosuid,noexec,nodev
|
|
|
|
[Install]
|
|
WantedBy=sysinit.target
|
|
EOF
|
|
|
|
# Create systemd service to set up cgroups
|
|
echo "🔧 Creating systemd service to set up cgroups..."
|
|
cat > /etc/systemd/system/setup-cgroups.service << 'EOF'
|
|
[Unit]
|
|
Description=Set up cgroups
|
|
After=sys-fs-cgroup.mount
|
|
DefaultDependencies=no
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=/bin/sh -c 'for subsystem in cpu cpuacct memory devices freezer net_cls blkio cpuset perf_event pids; do mkdir -p /sys/fs/cgroup/$subsystem; mount -t cgroup cgroup /sys/fs/cgroup/$subsystem; done'
|
|
RemainAfterExit=yes
|
|
|
|
[Install]
|
|
WantedBy=sysinit.target
|
|
EOF
|
|
|
|
# Enable systemd services
|
|
echo "🚀 Enabling systemd services..."
|
|
systemctl enable sys-fs-cgroup.mount
|
|
systemctl enable setup-cgroups.service
|
|
|
|
# Create a script to manually set up cgroups
|
|
echo "🔧 Creating manual cgroup setup script..."
|
|
cat > /usr/local/bin/setup-cgroups-manual.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Manual cgroup setup script
|
|
|
|
# Mount cgroup filesystem if not already mounted
|
|
if ! mountpoint -q /sys/fs/cgroup; then
|
|
echo "Mounting cgroup filesystem..."
|
|
mount -t cgroup cgroup /sys/fs/cgroup
|
|
fi
|
|
|
|
# Set up all cgroup subsystems
|
|
for subsystem in cpu cpuacct memory devices freezer net_cls blkio cpuset perf_event pids; do
|
|
if [ ! -d "/sys/fs/cgroup/$subsystem" ]; then
|
|
mkdir -p "/sys/fs/cgroup/$subsystem"
|
|
fi
|
|
if ! mountpoint -q "/sys/fs/cgroup/$subsystem"; then
|
|
echo "Mounting $subsystem subsystem..."
|
|
mount -t cgroup cgroup "/sys/fs/cgroup/$subsystem"
|
|
fi
|
|
done
|
|
|
|
# Verify pids subsystem is available
|
|
if [ -d /sys/fs/cgroup/pids ]; then
|
|
echo "✅ PIDS cgroup subsystem is available"
|
|
else
|
|
echo "❌ PIDS cgroup subsystem is not available"
|
|
fi
|
|
EOF
|
|
|
|
chmod +x /usr/local/bin/setup-cgroups-manual.sh
|
|
|
|
# Create a script to start container with proper cgroup settings
|
|
echo "🔧 Creating container startup script..."
|
|
cat > /usr/local/bin/start-qdrant-container.sh << 'EOF'
|
|
#!/bin/bash
|
|
# Script to start Qdrant container with proper cgroup settings
|
|
|
|
# Set up cgroups first
|
|
/usr/local/bin/setup-cgroups-manual.sh
|
|
|
|
# Start the container
|
|
echo "Starting Qdrant container..."
|
|
podman run -p 6333:6333 \
|
|
-v $(pwd)/data:/qdrant/storage \
|
|
hub.git4ta.fun/qdrant/qdrant
|
|
EOF
|
|
|
|
chmod +x /usr/local/bin/start-qdrant-container.sh
|
|
|
|
echo "✅ Systemd cgroup configuration complete!"
|
|
echo "🔄 Please reboot the system to ensure all changes take effect"
|
|
echo "After reboot, you can use '/usr/local/bin/start-qdrant-container.sh' to start your container"
|
|
echo "Alternatively, you can run '/usr/local/bin/setup-cgroups-manual.sh' before starting the container manually" |