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

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

test-prep

rsyslog-capture-daemon
service rsyslog force-reload

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

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

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

dpid=$(pidof hippotatd)

service hippotatd restart

dpid2=$(pidof hippotatd)

test $dpid != $dpid2

service hippotatd stop

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

t-ok
