mempool/production/bitcoind.freebsd

182 lines
3.9 KiB
Plaintext
Raw Normal View History

2020-10-23 13:35:20 +09:00
#!/bin/sh
# PROVIDE: bitcoind
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable :
# bitcoind_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable bitcoind
# bitcoind_user (str) Set to "bitcoin" by default.
# bitcoind_group (str) Set to "bitcoin" by default.
2020-10-23 22:11:32 +09:00
# bitcoind_conf (str) Set to "/bitcoin/bitcoind.conf" by default.
2020-10-23 13:35:20 +09:00
# bitcoind_data_dir (str) Set to "/var/db/bitcoin" by default.
2020-10-23 22:11:32 +09:00
# bitcoind_syslog_facility(str) Set to "local0" by default.
# bitcoind_syslog_priority(str) Set to "info" by default.
2020-10-23 13:35:20 +09:00
# bitcoindlimits_enable (bool) Set to "NO" by default.
# Set it to "YES" to enable bitcoindlimits
# bitcoindlimits_args Set to "-e -U ${bitcoind_user}" by default
. /etc/rc.subr
name="bitcoind"
rcvar=bitcoind_enable
start_precmd="bitcoind_precmd"
start_cmd="bitcoind_start"
restart_precmd="bitcoind_checkconfig"
reload_precmd="bitcoind_checkconfig"
configtest_cmd="bitcoind_checkconfig"
status_cmd="bitcoind_status"
stop_cmd="bitcoind_stop"
stop_postcmd="bitcoind_wait"
command="/usr/local/bin/bitcoind"
daemon_command="/usr/sbin/daemon"
2020-10-23 22:11:32 +09:00
pidfile="/bitcoin/bitcoind.pid"
2020-10-23 13:35:20 +09:00
extra_commands="configtest"
: ${bitcoind_enable:="NO"}
: ${bitcoindlimits_enable:="NO"}
load_rc_config ${name}
: ${bitcoind_user:="bitcoin"}
: ${bitcoind_group:="bitcoin"}
2020-10-23 22:11:32 +09:00
: ${bitcoind_data_dir:="/bitcoin"}
: ${bitcoind_config_file:="/bitcoin/bitcoin.conf"}
: ${bitcoind_syslog_facility:="local0"}
: ${bitcoind_syslog_priority:="info"}
: ${bitcoind_syslog_tag:="bitcoind"}
: ${bitcoind_kill_after:="300"}
2020-10-23 13:35:20 +09:00
: ${bitcoindlimits_args:="-e -U ${bitcoind_user}"}
# set up dependant variables
procname="${command}"
2020-10-23 22:11:32 +09:00
pidfile="${bitcoind_data_dir}/bitcoind.pid"
2020-10-23 13:35:20 +09:00
required_files="${bitcoind_config_file}"
bitcoind_checkconfig()
{
echo "Performing sanity check on bitcoind configuration:"
if [ ! -d "${bitcoind_data_dir}" ]
then
echo "Missing data directory: ${bitcoind_data_dir}"
exit 1
fi
chown -R "${bitcoind_user}:${bitcoind_group}" "${bitcoind_data_dir}"
if [ ! -f "${bitcoind_config_file}" ]
then
echo "Missing configuration file: ${bitcoind_config_file}"
exit 1
fi
if [ ! -x "${command}" ]
then
echo "Missing executable: ${command}"
exit 1
fi
return 0
}
bitcoind_cleanup()
{
rm -f "${pidfile}"
}
bitcoind_precmd()
{
bitcoind_checkconfig
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
rm -f "${pidfile}"
fi
if checkyesno bitcoindlimits_enable
then
eval $(/usr/bin/limits ${bitcoindlimits_args}) 2>/dev/null
else
return 0
fi
}
bitcoind_status()
{
local pid
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
echo "Bitcoind running, pid: ${pid}"
fi
}
bitcoind_start()
{
echo "Starting bitcoind:"
cd "${bitcoind_data_dir}" || return 1
2020-10-23 22:11:32 +09:00
${daemon_command} \
-u "${bitcoind_user}" \
-l "${bitcoind_syslog_facility}" \
-s "${bitcoind_syslog_priority}" \
-T "${bitcoind_syslog_tag}" \
2020-10-23 13:35:20 +09:00
${command} \
2020-10-23 22:11:32 +09:00
-printtoconsole=1 \
2020-10-23 13:35:20 +09:00
-conf="${bitcoind_config_file}" \
-datadir="${bitcoind_data_dir}"
}
bitcoind_stop()
{
echo "Stopping bitcoind:"
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
kill ${pid}
fi
}
bitcoind_wait()
{
2020-10-23 22:11:32 +09:00
local n="${bitcoind_kill_after}"
2020-10-23 13:35:20 +09:00
echo "Waiting for bitcoind shutdown:"
while :
do
printf '.'
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
printf '\n'
break
fi
sleep 1
n=$((${n} - 1))
if [ ${n} -eq 0 -a -f "${pidfile}" ]
then
printf "\nForce shutdown"
kill -9 $(cat "${pidfile}")
for n in 1 2 3
do
printf '.'
sleep 1
done
printf '\n'
break
fi
done
rm -f "${pidfile}"
echo "Shutdown complete"
}
run_rc_command "$1"