freedive/priv/freebsd/service.sh.eex

57 lines
1.4 KiB
Elixir

#!bin/sh
# PROVIDE: <%= @name %>
# REQUIRE: LOGIN
# REQUIRE: DAEMON
<%= @name %>_enable=${<%= @name %>_enable:-"NO"}
. /etc/rc.subr
: ${<%= @name %>_env_file:="<%= @env_file %>"}
name="<%= @name %>"
<%= @name %>_user="<%= @user %>"
<%= @name %>_group="<%= @group %>"
rcvar="<%= @name %>_enable"
command="<%= @app_dir %>/bin/<%= @name %>"
pidfile="<%= @run_dir %>/<%= @name %>.pid"
confdir="<%= @conf_dir %>"
logfile="<%= @log_dir %>/<%= @name %>.log"
extra_commands="<%= Enum.join(@service_commands, " ") %>"
procname=${command}
start_cmd="<%= @name %>_start"
stop_cmd="${command} stop"
<%= for cmd <- @service_commands do %>
<%= cmd %>_cmd="<%= @app_dir %>/<%= cmd %>.sh"
<% end %>
<%= @name %>_start() {
# Stop here if not running as root
if [ `id -u` -ne 0 ]; then
echo "You must be root to start <%= @name %>"
return 1
fi
: "${ERL_CRASH_DUMP:="<%= @run_dir %>/erl_crash.dump"}"
export ERL_CRASH_DUMP
if [ -f ${pidfile} ]; then
echo "Pidfile ${pidfile} exists. Is <%= @name %> running?"
return 1
fi
if [ -f ${ERL_CRASH_DUMP} ]; then
echo "Removing old crash dump file ${ERL_CRASH_DUMP}"
rm -f ${ERL_CRASH_DUMP}
fi
echo "Starting <%= @name %> as user <%= @user %>"
echo "Logs will be written to ${logfile}"
daemon -t ${name} -p ${pidfile} -f -H -o ${logfile} -u <%= @user %> ${command} start
}
load_rc_config ${name}
run_rc_command "$1"