#!/bin/sh

# PROVIDE: esecanna
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# esecanna_enable (bool):   Set to NO by default.
#               Set it to YES to enable esecanna.

. /etc/rc.subr

name=esecanna
rcvar=esecanna_enable

esecannaserver=%%PREFIX%%/sbin/esecannaserver

# XXX
command=/usr/bin/nohup
command_args=">/dev/null $esecannaserver"
procname=$esecannaserver

pidfile=/var/run/esecanna/esecanna.pid
esecanna_chdir="$(dirname $pidfile)"
required_files=%%PREFIX%%/etc/esecannarc

start_precmd="esecanna_prestart"

esecanna_prestart ()  {
	if [ -f %%PREFIX%%/vje30/.version ] \
	   && grep -qw 'FREE TRIAL VERSION' %%PREFIX%%/vje30/.version; then
		echo '** Using VJE-Delta 3.0 trial, it is unable to connect to vjed on startup.'
		echo '** Please execute $esecannaserver manually after once you run vje.'
		exit 255
	fi

	/bin/rm -f /tmp/.iroha_unix/IROHA

	/bin/mkdir -p /var/run/esecanna
}

load_rc_config $name

: ${esecanna_enable="NO"}

run_rc_command "$1"
