#!/bin/sh

set -e

cleanup () {
  service dlm stop
  service corosync stop
}

trap "cleanup" 0 2 3 15

# configure cluster
printf "\n=== corosync ===\n"
corosync-quorumtool -e 1
corosync-quorumtool || true

printf "\n=== dlm.ko ===\n"
lsmod | grep dlm || true
ls -l /dev/dlm* || true
ls -l /dev/misc/dlm* || true
dmesg | tail

printf "\n=== dlm_controld ===\n"
if ! service dlm status; then
  # service log might be incomplete
  if [ -x /bin/journalctl ]; then
    journalctl -b > $AUTOPKGTEST_ARTIFACTS/journal.log
  fi
  exit 1
fi

printf "\n=== dlm_tool status ===\n"
dlm_tool status

printf "\n=== dlm_tool dump ===\n"
dlm_tool dump

printf "\n=== dlm_tool dump_config ===\n"
dlm_tool dump_config

printf "\n=== dlm_tool join test ===\n"
dlm_tool join test

printf "\n=== dlm_tool ls ===\n"
dlm_tool ls

printf "\n=== dlm_tool leave test ===\n"
dlm_tool leave test
