#!/bin/bash

CAD=../check.avail
CDD=/etc/statusd/check.d

function addcheck()
{
	RF=$1
	if ! [ -L $CDD/$RF ]; then
		ln -s $CAD/$RF $CDD/$RF
	fi
}

OLDCHECKNO=`find $CDD/ -type f |wc -l`

if [ $OLDCHECKNO -lt 1 ]; then

	# DEFAULT CHECKS

	addcheck df
	addcheck load
	addcheck resolver

fi

# systemd
#if [ -d /run/systemd/system ] ; then
#	systemctl --system daemon-reload >/dev/null || true
#fi

deb-systemd-helper unmask statusd.socket >/dev/null || true
if deb-systemd-helper --quiet was-enabled statusd.socket; then
	deb-systemd-helper enable statusd.socket >/dev/null || true
	systemctl start statusd.socket || true
else
	deb-systemd-helper update-state statusd.socket >/dev/null || true
fi


if ! [ -d /run/systemd/system ]; then

	echo "no systemd - don't forget to set up openbsd-inetd:"
	echo
	echo "/etc/inetd.conf:"
	echo
	echo "# STATUSd"
	echo "34000	stream	tcp	nowait	root	/etc/statusd/statusd"
	echo
	echo "And restart inetd: /etc/init.d/openbsd-inetd restart"

fi
