#!/bin/sh

set -e

# https://bugs.launchpad.net/bugs/1828228
ulimit -H -l unlimited 2>/dev/null || {
        echo "test disabled for unprivileged namespaces"
        exit 77
}

# allow sbd to start without a real watchdog device
if ! [ -e /dev/watchdog ]; then
  sed -i 's|/dev/watchdog|/dev/null|' /etc/default/sbd
fi

# get systemd to pickup the corosync dependency on sbd
if [ -d /run/systemd/system ]; then
  systemctl daemon-reload
fi

# corosync should now also start sbd automatically
service corosync restart

for i in $(seq 1 60); do
  pgrep --list-full sbd && exit 0
  sleep 1
done

echo "sbd failed to start"
exit 1
