#!/bin/bash
#
# Tests that we can start, stop, and restart.

set -e
. "${0%/*}"/acommon

test-prep

rsyslog-capture-daemon
service rsyslog force-reload

sleep 5 # dunno if this will help

perl <test/test.cfg >/etc/hippotat/main.cfg -pe '
	s{^addrs *=.*}{addrs = 127.0.0.1};
'

cat >>/etc/default/hippotatd <<END
set -x
CHECK_FIREWALL=false
USER=root
END

service hippotatd start

sleep 5 # dunno if this will help?

set +e
ps -He
systemctl is-active hippotatd.service ||:
journalctl -u hippotatd.service ||:
egrep . /dev/null /var/log/*.log
egrep . /dev/null /etc/systemd/journald.conf
egrep . /dev/null /etc/rsyslog.conf
set -e

curl http://localhost:8099/ | tee /dev/stderr | grep hippotat

dpid=$(pidof hippotatd)

service hippotatd restart

sleep 5 # dunno if this will help?

dpid2=$(pidof hippotatd)

test $dpid != $dpid2

service hippotatd stop

sleep 5 # dunno if this will help?

( LC_MESSAGES=C nc -v localhost 8099 2>&1 ||: ) \
    | tee /dev/stderr | grep 'Connection refused'

t-ok
