#!/bin/sh

set -e

cleanup () {
  service pcsd stop
  service pacemaker stop
  service corosync stop
  passwd --delete --lock hacluster
}

trap "cleanup" 0 2 3 15

# crm cluster init fails if hacluster account is expired
chage -E -1 hacluster

echo hacluster:hacluster | chpasswd
pcs cluster auth -u hacluster -p hacluster
pcs cluster setup debian node1 --force

# Corosync did not start if the test container is unprivileged
if ! ulimit -H -l unlimited 2>/dev/null; then
  printf 'system.allow_knet_handle_fallback: yes\n' >>/etc/corosync/corosync.conf
fi

pcs cluster start

sleep 60

pcs pcsd status | grep -20 "node1: Online"
