mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 01:39:34 +08:00
Handle systemd nvidia rules automatically during agent installation
This commit is contained in:
@@ -264,7 +264,7 @@ if [ -n "$GITHUB_PROXY_URL" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to check if a package is installed
|
# Check if a package is installed
|
||||||
package_installed() {
|
package_installed() {
|
||||||
command -v "$1" >/dev/null 2>&1
|
command -v "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
@@ -389,6 +389,17 @@ set_selinux_context
|
|||||||
# Cleanup
|
# Cleanup
|
||||||
rm -rf "$TEMP_DIR"
|
rm -rf "$TEMP_DIR"
|
||||||
|
|
||||||
|
# Check for NVIDIA GPUs and grant device permissions for systemd service
|
||||||
|
detect_nvidia_devices() {
|
||||||
|
local devices=""
|
||||||
|
for i in /dev/nvidia*; do
|
||||||
|
if [ -e "$i" ]; then
|
||||||
|
devices="${devices}DeviceAllow=$i rw\n"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "$devices"
|
||||||
|
}
|
||||||
|
|
||||||
# Modify service installation part, add Alpine check before systemd service creation
|
# Modify service installation part, add Alpine check before systemd service creation
|
||||||
if is_alpine; then
|
if is_alpine; then
|
||||||
echo "Creating OpenRC service for Alpine Linux..."
|
echo "Creating OpenRC service for Alpine Linux..."
|
||||||
@@ -560,6 +571,10 @@ EOF
|
|||||||
else
|
else
|
||||||
# Original systemd service installation code
|
# Original systemd service installation code
|
||||||
echo "Creating the systemd service for the agent..."
|
echo "Creating the systemd service for the agent..."
|
||||||
|
|
||||||
|
# Detect NVIDIA devices and grant device permissions
|
||||||
|
NVIDIA_DEVICES=$(detect_nvidia_devices)
|
||||||
|
|
||||||
cat >/etc/systemd/system/beszel-agent.service <<EOF
|
cat >/etc/systemd/system/beszel-agent.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Beszel Agent Service
|
Description=Beszel Agent Service
|
||||||
@@ -589,6 +604,8 @@ RemoveIPC=yes
|
|||||||
RestrictSUIDSGID=true
|
RestrictSUIDSGID=true
|
||||||
SystemCallArchitectures=native
|
SystemCallArchitectures=native
|
||||||
|
|
||||||
|
$(if [ -n "$NVIDIA_DEVICES" ]; then printf "%b" "# NVIDIA device permissions\n${NVIDIA_DEVICES}"; fi)
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
|
Reference in New Issue
Block a user