Last active
November 5, 2023 20:28
-
-
Save wpoely86/cf88e8e41ee885677082a7b08e12ae11 to your computer and use it in GitHub Desktop.
Script and systemd unit to wait until at least one infiniband interface is active
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=Wait for infiniband to become active | |
Wants=network-online.target | |
After=network-online.target | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/bin/waitforib.sh | |
RemainAfterExit=yes | |
[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 | |
# Search for infiniband devices and check waits until | |
# at least one reports that it is ACTIVE | |
if [[ ! -d /sys/class/infiniband ]] | |
then | |
logger "No infiniband found" | |
exit 0 | |
fi | |
ports=$(ls /sys/class/infiniband/*/ports/*/state) | |
for (( count = 0; count < 300; count++ )) | |
do | |
for port in ${ports}; do | |
if grep -qc ACTIVE $port; then | |
logger "Infiniband online at $port" | |
exit 0 | |
fi | |
done | |
sleep 1 | |
done | |
logger "Failed to find an active infiniband interface" | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment