#!/bin/sh

### BEGIN INIT INFO
# Provides:		irkerhook-lxc
# Required-Start:	$remote_fs
# Required-Stop:	$remote_fs
# Should-Start:		irker
# Should-Stop:		irker
# Default-Start:	2 3 4 5
# Default-Stop:		0 6
# Short-Description:	irkerhook-lxc
# Description:		irkerhook-lxc
# X-Start-Before:	lxc
# X-Stop-After:
# X-Interactive:	true
### END INIT INFO


set -e

if [ ! -x /usr/bin/irkerhook-lxc ] || [ ! -x /usr/bin/irkerd ]
then
	exit 0
fi

for _FILE in /etc/default/irkerhook-lxc /etc/default/irkerhook-lxc.d/*
do
	if [ -f "${_FILE}" ]
	then
		. "${_FILE}" || true
	fi
done

if [ "${IRK_ENABLED}" != "true" ]
then
	exit 0
fi

. /lib/lsb/init-functions

case "${1}" in
	start)
		log_daemon_msg "Starting irkerhook-lxc"
		sleep 1

		_KERNEL="$(uname -r)"
		irkerhook-lxc "\x0312$(hostname -f):\x03 host system \x0303started\x03 (linux ${_KERNEL})"
		;;

	stop)
		log_daemon_msg "Stopping irkerhook-lxc"

		_UPTIME="$(uptime | sed -e 's|.*up ||' -e 's|,.*||')"
		irkerhook-lxc "\x0312$(hostname -f):\x03 host system \x0304stopped\x03 (uptime ${_UPTIME})"
		;;

	restart|force-reload)

		;;

	*)
		log_success_msg "Usage: ${0} {start|stop}"
		exit 1
		;;
esac

exit 0
