#!/bin/bash
#
#  Copyright (C) 2011-2016, it-novum GmbH <community@openattic.org>
#
#  openATTIC is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; version 2.
#
#  This package is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

set -u

BEFORE=`date +%s.%N`
OUT="`dbus-send --system --dest=org.openattic.systemd --print-reply=literal / org.openattic.systemd.ping 2>/dev/null`"
AFTER=`date +%s.%N`

MILLIS=`echo "$AFTER - $BEFORE" | bc`

if [ "$OUT" = "   pong" ]; then
    echo "Systemd responded to DBus ping.|time=${MILLIS}s"
    exit 0
else
    echo "Systemd did not respond to DBus ping."
    exit 2
fi
