Created
November 12, 2021 16:10
-
-
Save kralicky/43bd9ab885da03545134a1cdf484b1ad to your computer and use it in GitHub Desktop.
VGPU mediated device persistence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Start defined mediated devices | |
Requires=nvidia-vgpu-mgr.service | |
Requires=nvidia-vgpud.service | |
After=nvidia-vgpu-mgr.service | |
After=nvidia-vgpud.service | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/start-defined-vgpus.sh | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
while true; do | |
devices=$(/usr/local/bin/mdevctl list -d | grep -v '\(active\)' | awk '{ printf "%s ",$1 }') | |
if [ -z "$devices" ]; then | |
echo "No unstarted mediated devices found." | |
exit 0 | |
fi | |
num=$(echo "$devices" | wc -w) | |
echo "Attempting to start $num mediated devices" | |
for device in $devices; do | |
/usr/local/bin/mdevctl start --uuid $device | |
if [ $? -ne 0 ]; then | |
echo "Failed to start device $device, will retry in 10 seconds." | |
sleep 10 | |
continue 2 | |
else | |
echo "Successfully started device $device" | |
fi | |
done | |
echo "Successfully started $num devices." | |
exit 0 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment