#!/bin/sh

# PROVIDE: epmd
# REQUIRE: DAEMON mountlate
#
# Add the following line to /etc/rc.conf to enable epmd:
#
# epmd_enable="YES"
#
# Configure optional flags with:
# epmd_opts="-address 127.0.0.1"

. /etc/rc.subr

name=epmd
rcvar=epmd_enable

load_rc_config ${name}

: ${epmd_enable="NO"}
: ${epmd_opts:-""}
: ${epmd_user="beam"}

procname="daemon"
pidfile="/var/run/epmd/epmd.pid"
command="/usr/sbin/daemon"
command_args="-f -r -P ${pidfile} %%PREFIX%%/bin/epmd ${epmd_opts}"
command_user="${epmd_user}"

start_precmd="epmd_precmd"

epmd_precmd()
{
	if [ ! -d "/var/run/epmd" ]; then
		install -d -o ${epmd_user} -g ${epmd_user} /var/run/epmd
	fi
	# Ensure beam user can write pidfile
	install -m 644 -g ${epmd_user} -o ${epmd_user} /dev/null ${pidfile}
}

run_rc_command "$1"
