Skip to content

Instantly share code, notes, and snippets.

@wpoely86
Last active November 5, 2023 20:28
Show Gist options
  • Save wpoely86/cf88e8e41ee885677082a7b08e12ae11 to your computer and use it in GitHub Desktop.
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
[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
#!/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