#!/bin/sh

if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/${0##*/}\$"); then
    echo "$0: Cannot determine the PREFIX" >&2
    exit 64
fi


case "$1" in
start)
	if [ -x ${PREFIX}/sbin/cannaserver ]; then
		/bin/rm -f /tmp/.iroha_unix/IROHA
		/usr/bin/touch /var/log/CANNA0msgs
		/usr/sbin/chown bin:bin /var/log/CANNA0msgs
		${PREFIX}/sbin/cannaserver && echo -n ' canna'
	fi
	;;
stop)
	${PREFIX}/sbin/cannakill && echo -n ' canna'
	;;
*)
	echo "Usage: `basename $0` {start|stop}" >&2
	exit 64
	;;
esac

exit 0
