#!/bin/sh # 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 load_rc_config $name : ${%%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 cli_command=%%PREFIX%%/bin/%%PORTNAME%%-cli %%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" reindex_cmd="${name}_reindex" salvage_cmd="${name}_salvage" extra_commands="reindex salvage" %%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 ${cli_command} -conf=${%%PORTNAME%%_config} -datadir=${%%PORTNAME%%_datadir} stop wait_for_pids ${rc_pid} } %%PORTNAME%%_reindex() { if [ -z "$rc_fast" -a -n "$rc_pid" ]; then %%PORTNAME%%_stop fi echo "Reindexing ${name} blockchain." command_args="${command_args} -reindex" eval ${command} ${command_args} } %%PORTNAME%%_salvage() { if [ -z "$rc_fast" -a -n "$rc_pid" ]; then %%PORTNAME%%_stop fi echo "Attempting to salvage ${name} walllet." command_args="${command_args} -salvagewallet" eval ${command} ${command_args} } run_rc_command "$1"