-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
65 lines (54 loc) · 1.81 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Helpful to read output when debugging
#set -x
echo "Stopping nvidia-persistenced.service..."
systemctl stop nvidia-persistenced.service
echo "Stopping coolercontrold.service..."
systemctl stop coolercontrold.service
echo "Stopping ollama.service..."
systemctl stop ollama.service
echo "Stopping comfyui.service..."
systemctl stop comfyui.service
echo "Checking for processes using /dev/nvidia*..."
# Use lsof to find processes using /dev/nvidia* and extract their PIDs
pids=$(lsof -t /dev/nvidia* /dev/dri/card0* /proc/driver/nvidia* 2>/dev/null)
if [ -n "$pids" ]; then
echo "Found processes using /dev/nvidia*: $pids"
echo "Attempting to kill these processes..."
# Try to kill the processes gracefully first
for pid in $pids; do
if kill $pid; then
echo "Process $pid terminated successfully."
else
echo "Failed to terminate process $pid. Trying a forceful kill..."
kill -9 $pid
fi
done
echo "All processes using /dev/nvidia* have been terminated."
else
echo "No processes are using /dev/nvidia*."
fi
echo "Unbinding VTconsoles..."
#echo 0 > /sys/class/vtconsole/vtcon0/bind
#echo 0 > /sys/class/vtconsole/vtcon1/bind
echo "Unbinding EFI-Framebuffer..."
#echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
echo "Sleeping for 5 seconds to avoid race conditions..."
sleep 5
echo "Unloading Nvidia drivers..."
modprobe -r nvidia_uvm
modprobe -r nvidia_drm
modprobe -r nvidia_modeset
modprobe -r i2c_nvidia_gpu
modprobe -r nvidia
echo "Detaching GPU devices..."
virsh nodedev-detach pci_0000_01_00_0
virsh nodedev-detach pci_0000_01_00_1
echo "Loading VFIO kernel modules..."
modprobe vfio
modprobe vfio_pci
modprobe vfio_iommu_type1
echo "Starting coolercontrold.service..."
systemctl start coolercontrold.service
#echo "Set LGTV to input 2..."
#lgtv setInput HDMI_2