7d2c34ff18
- Use options helpers - Use @sample PR: 192413 Submitted by: maintainer
76 lines
2 KiB
Bash
76 lines
2 KiB
Bash
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
# PROVIDE: %%PORTNAME%%
|
|
# REQUIRE: LOGIN
|
|
# KEYWORD: shutdown
|
|
|
|
#
|
|
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
|
|
# to enable this service:
|
|
#
|
|
# %%PORTNAME%%_enable (bool): Set to NO by default.
|
|
# Set it to YES to enable %%PORTNAME%%.
|
|
# %%PORTNAME%%_config (path): Set to %%PREFIX%%/etc/%%PORTNAME%%.conf
|
|
# by default.
|
|
# %%PORTNAME%%_user: The user account %%PORTNAME%% daemon runs as
|
|
# It uses '%%PORTNAME%%' user by default.
|
|
# %%PORTNAME%%_group: The group account %%PORTNAME%% daemon runs as
|
|
# It uses '%%PORTNAME%%' group by default.
|
|
# %%PORTNAME%%_datadir (str): Default to "/var/db/%%PORTNAME%%"
|
|
# Base data directory.
|
|
|
|
. /etc/rc.subr
|
|
|
|
name=%%PORTNAME%%
|
|
rcvar=%%PORTNAME%%_enable
|
|
|
|
: ${%%PORTNAME%%_enable:=NO}
|
|
: ${%%PORTNAME%%_config=%%PREFIX%%/etc/%%PORTNAME%%.conf}
|
|
: ${%%PORTNAME%%_datadir=/var/db/%%PORTNAME%%}
|
|
: ${%%PORTNAME%%_user="%%PORTNAME%%"}
|
|
: ${%%PORTNAME%%_group="%%PORTNAME%%"}
|
|
|
|
required_files=${%%PORTNAME%%_config}
|
|
command=%%PREFIX%%/bin/%%PORTNAME%%d
|
|
%%PORTNAME%%_chdir=${%%PORTNAME%%_datadir}
|
|
pidfile="${%%PORTNAME%%_datadir}/%%PORTNAME%%d.pid"
|
|
stop_cmd=%%PORTNAME%%_stop
|
|
command_args="-conf=${%%PORTNAME%%_config} -datadir=${%%PORTNAME%%_datadir} -noupnp -daemon -pid=${pidfile}"
|
|
start_precmd="${name}_prestart"
|
|
|
|
%%PORTNAME%%_create_datadir()
|
|
{
|
|
echo "Creating data directory"
|
|
eval mkdir -p ${%%PORTNAME%%_datadir}
|
|
[ $? -eq 0 ] && chown -R ${%%PORTNAME%%_user}:${%%PORTNAME%%_group} ${%%PORTNAME%%_datadir}
|
|
}
|
|
|
|
%%PORTNAME%%_prestart()
|
|
{
|
|
if [ ! -d "${%%PORTNAME%%_datadir}/." ]; then
|
|
%%PORTNAME%%_create_datadir || return 1
|
|
fi
|
|
}
|
|
|
|
%%PORTNAME%%_requirepidfile()
|
|
{
|
|
if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
|
|
echo "${name} not running? (check $pidfile)."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
%%PORTNAME%%_stop()
|
|
{
|
|
%%PORTNAME%%_requirepidfile
|
|
|
|
echo "Stopping ${name}."
|
|
eval ${command} -conf=${%%PORTNAME%%_config} -datadir=${%%PORTNAME%%_datadir} stop
|
|
wait_for_pids ${rc_pid}
|
|
}
|
|
|
|
load_rc_config $name
|
|
run_rc_command "$1"
|