From cd11eb8ac19e963539bd17e9a1c453a26df99991 Mon Sep 17 00:00:00 2001 From: wiz Date: Sat, 24 Oct 2020 11:04:41 +0900 Subject: [PATCH] Add updated rc.d scripts and rc.conf for FreeBSD install --- production/bitcoind.freebsd | 181 -------------------------------- production/rc.conf | 39 +++++++ production/rc.d/bitcoin | 179 +++++++++++++++++++++++++++++++ production/rc.d/bitcoin_testnet | 180 +++++++++++++++++++++++++++++++ 4 files changed, 398 insertions(+), 181 deletions(-) delete mode 100644 production/bitcoind.freebsd create mode 100644 production/rc.conf create mode 100644 production/rc.d/bitcoin create mode 100644 production/rc.d/bitcoin_testnet diff --git a/production/bitcoind.freebsd b/production/bitcoind.freebsd deleted file mode 100644 index 716e6a443..000000000 --- a/production/bitcoind.freebsd +++ /dev/null @@ -1,181 +0,0 @@ -#!/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. -# bitcoind_conf (str) Set to "/bitcoin/bitcoind.conf" by default. -# bitcoind_data_dir (str) Set to "/var/db/bitcoin" by default. -# bitcoind_syslog_facility(str) Set to "local0" by default. -# bitcoind_syslog_priority(str) Set to "info" by default. -# 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" -pidfile="/bitcoin/bitcoind.pid" -extra_commands="configtest" - - -: ${bitcoind_enable:="NO"} -: ${bitcoindlimits_enable:="NO"} - -load_rc_config ${name} - -: ${bitcoind_user:="bitcoin"} -: ${bitcoind_group:="bitcoin"} -: ${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"} -: ${bitcoindlimits_args:="-e -U ${bitcoind_user}"} - -# set up dependant variables -procname="${command}" -pidfile="${bitcoind_data_dir}/bitcoind.pid" -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 - ${daemon_command} \ - -u "${bitcoind_user}" \ - -l "${bitcoind_syslog_facility}" \ - -s "${bitcoind_syslog_priority}" \ - -T "${bitcoind_syslog_tag}" \ - ${command} \ - -printtoconsole=1 \ - -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() -{ - local n="${bitcoind_kill_after}" - 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" diff --git a/production/rc.conf b/production/rc.conf new file mode 100644 index 000000000..f10505210 --- /dev/null +++ b/production/rc.conf @@ -0,0 +1,39 @@ +zfs_enable="YES" +sendmail_enable="NONE" +clear_tmp_enable="YES" +syslogd_flags="-b 127.0.0.1" +dumpdev="NO" + +hostname="mempool.local" +ifconfig_genet0="DHCP" +local_unbound_enable="YES" + +ntpdate_enable="YES" +ntpdate_hosts="time.nist.gov" + +sshd_enable="NO" +openssh_enable="YES" +openssh_flags=" \ +-o 'Port 22' \ +-o 'UseDNS no' \ +-o 'KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256' \ +-o 'AuthenticationMethods publickey,keyboard-interactive' \ +-o 'PermitRootLogin no' \ +" + +firewall_enable="YES" +firewall_quiet="YES" +firewall_type="workstation" +firewall_myservices="8333/tcp" +firewall_allowservices="any" +firewall_logdeny="YES" +firewall_trusted="192.168.0.0/16,172.16.0.0/12,10.0.0.0/8" + +bitcoin_enable="YES" +bitcoin_testnet_enable="YES" + +nginx_enable="YES" +tor_enable="YES" + +mysql_enable="YES" +mysql_dbdir="/mysql" diff --git a/production/rc.d/bitcoin b/production/rc.d/bitcoin new file mode 100644 index 000000000..76c217589 --- /dev/null +++ b/production/rc.d/bitcoin @@ -0,0 +1,179 @@ +#!/bin/sh +# PROVIDE: bitcoin +# REQUIRE: LOGIN cleanvar +# KEYWORD: shutdown + +# +# Add the following lines to /etc/rc.conf to enable : +# bitcoin_enable (bool): Set to "NO" by default. +# Set it to "YES" to enable bitcoin +# bitcoin_user (str) Set to "bitcoin" by default. +# bitcoin_group (str) Set to "bitcoin" by default. +# bitcoin_conf (str) Set to "/bitcoin/bitcoin.conf" by default. +# bitcoin_data_dir (str) Set to "/bitcoin" by default. +# bitcoin_syslog_facility(str) Set to "local0" by default. +# bitcoin_syslog_priority(str) Set to "info" by default. +# bitcoinlimits_enable (bool) Set to "NO" by default. +# Set it to "YES" to enable bitcoinlimits +# bitcoinlimits_args Set to "-e -U ${bitcoin_user}" by default + + +. /etc/rc.subr + +name="bitcoin" +rcvar=bitcoin_enable + +start_precmd="bitcoin_precmd" +start_cmd="bitcoin_start" +restart_precmd="bitcoin_checkconfig" +reload_precmd="bitcoin_checkconfig" +configtest_cmd="bitcoin_checkconfig" +status_cmd="bitcoin_status" +stop_cmd="bitcoin_stop" +stop_postcmd="bitcoin_wait" +command="/usr/local/bin/bitcoind" +daemon_command="/usr/sbin/daemon" +extra_commands="configtest" +pidfile="/bitcoin/bitcoind.pid" + +: ${bitcoin_enable:="NO"} +: ${bitcoinlimits_enable:="NO"} + +load_rc_config ${name} + +: ${bitcoin_user:="bitcoin"} +: ${bitcoin_group:="bitcoin"} +: ${bitcoin_data_dir:="/bitcoin"} +: ${bitcoin_config_file:="/bitcoin/bitcoin.conf"} +: ${bitcoin_syslog_facility:="local0"} +: ${bitcoin_syslog_priority:="info"} +: ${bitcoin_syslog_tag:="bitcoin"} +: ${bitcoin_kill_after:="300"} +: ${bitcoinlimits_args:="-e -U ${bitcoin_user}"} + +# set up dependant variables +procname="${command}" +required_files="${bitcoin_config_file}" +pidfile="${bitcoin_data_dir}/bitcoind.pid" + +bitcoin_checkconfig() +{ + echo "Performing sanity check on bitcoin configuration:" + if [ ! -d "${bitcoin_data_dir}" ] + then + echo "Missing data directory: ${bitcoin_data_dir}" + exit 1 + fi + chown -R "${bitcoin_user}:${bitcoin_group}" "${bitcoin_data_dir}" + + if [ ! -f "${bitcoin_config_file}" ] + then + echo "Missing configuration file: ${bitcoin_config_file}" + exit 1 + fi + if [ ! -x "${command}" ] + then + echo "Missing executable: ${command}" + exit 1 + fi + return 0 +} + +bitcoin_cleanup() +{ + rm -f "${pidfile}" +} + +bitcoin_precmd() +{ + bitcoin_checkconfig + + pid=$(check_pidfile "${pidfile}" "${procname}") + if [ -z "${pid}" ] + then + echo "Bitcoind is not running" + rm -f "${pidfile}" + fi + + if checkyesno bitcoinlimits_enable + then + eval $(/usr/bin/limits ${bitcoinlimits_args}) 2>/dev/null + else + return 0 + fi +} + +bitcoin_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 +} + +bitcoin_start() +{ + echo "Starting bitcoin:" + cd "${bitcoin_data_dir}" || return 1 + ${daemon_command} \ + -u "${bitcoin_user}" \ + -l "${bitcoin_syslog_facility}" \ + -s "${bitcoin_syslog_priority}" \ + -T "${bitcoin_syslog_tag}" \ + ${command} \ + -printtoconsole=1 \ + -conf="${bitcoin_config_file}" \ + -datadir="${bitcoin_data_dir}" +} + +bitcoin_stop() +{ + echo "Stopping bitcoin:" + pid=$(check_pidfile "${pidfile}" "${procname}") + if [ -z "${pid}" ] + then + echo "Bitcoind is not running" + return 1 + else + kill ${pid} + fi +} + +bitcoin_wait() +{ + local n="${bitcoin_kill_after}" + echo "Waiting for bitcoin 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" diff --git a/production/rc.d/bitcoin_testnet b/production/rc.d/bitcoin_testnet new file mode 100644 index 000000000..b15642413 --- /dev/null +++ b/production/rc.d/bitcoin_testnet @@ -0,0 +1,180 @@ +#!/bin/sh +# PROVIDE: bitcoin_testnet +# REQUIRE: LOGIN cleanvar +# KEYWORD: shutdown + +# +# Add the following lines to /etc/rc.conf to enable : +# bitcoin_testnet_enable (bool): Set to "NO" by default. +# Set it to "YES" to enable bitcoin +# bitcoin_testnet_user (str) Set to "bitcoin" by default. +# bitcoin_testnet_group (str) Set to "bitcoin" by default. +# bitcoin_testnet_conf (str) Set to "/bitcoin/bitcoin.conf" by default. +# bitcoin_testnet_data_dir (str) Set to "/var/db/bitcoin" by default. +# bitcoin_testnet_syslog_facility(str) Set to "local0" by default. +# bitcoin_testnet_syslog_priority(str) Set to "info" by default. +# bitcoinlimits_enable (bool) Set to "NO" by default. +# Set it to "YES" to enable bitcoinlimits +# bitcoinlimits_args Set to "-e -U ${bitcoin_testnet_user}" by default + + +. /etc/rc.subr + +name="bitcoin_testnet" +rcvar=bitcoin_testnet_enable + +start_precmd="bitcoin_testnet_precmd" +start_cmd="bitcoin_testnet_start" +restart_precmd="bitcoin_testnet_checkconfig" +reload_precmd="bitcoin_testnet_checkconfig" +configtest_cmd="bitcoin_testnet_checkconfig" +status_cmd="bitcoin_testnet_status" +stop_cmd="bitcoin_testnet_stop" +stop_postcmd="bitcoin_testnet_wait" +command="/usr/local/bin/bitcoind" +daemon_command="/usr/sbin/daemon" +extra_commands="configtest" +pidfile="/bitcoin/bitcoin.pid" + +: ${bitcoin_testnet_enable:="NO"} +: ${bitcoinlimits_enable:="NO"} + +load_rc_config ${name} + +: ${bitcoin_testnet_user:="bitcoin"} +: ${bitcoin_testnet_group:="bitcoin"} +: ${bitcoin_testnet_data_dir:="/bitcoin"} +: ${bitcoin_testnet_config_file:="/bitcoin/bitcoin.conf"} +: ${bitcoin_testnet_syslog_facility:="local0"} +: ${bitcoin_testnet_syslog_priority:="info"} +: ${bitcoin_testnet_syslog_tag:="bitcoin"} +: ${bitcoin_testnet_kill_after:="300"} +: ${bitcoinlimits_args:="-e -U ${bitcoin_testnet_user}"} + +# set up dependant variables +procname="${command}" +required_files="${bitcoin_testnet_config_file}" +pidfile="${bitcoin_testnet_data_dir}/testnet3/bitcoind.pid" + +bitcoin_testnet_checkconfig() +{ + echo "Performing sanity check on bitcoin configuration:" + if [ ! -d "${bitcoin_testnet_data_dir}" ] + then + echo "Missing data directory: ${bitcoin_testnet_data_dir}" + exit 1 + fi + chown -R "${bitcoin_testnet_user}:${bitcoin_testnet_group}" "${bitcoin_testnet_data_dir}" + + if [ ! -f "${bitcoin_testnet_config_file}" ] + then + echo "Missing configuration file: ${bitcoin_testnet_config_file}" + exit 1 + fi + if [ ! -x "${command}" ] + then + echo "Missing executable: ${command}" + exit 1 + fi + return 0 +} + +bitcoin_testnet_cleanup() +{ + rm -f "${pidfile}" +} + +bitcoin_testnet_precmd() +{ + bitcoin_testnet_checkconfig + + pid=$(check_pidfile "${pidfile}" "${procname}") + if [ -z "${pid}" ] + then + echo "Bitcoind is not running" + rm -f "${pidfile}" + fi + + if checkyesno bitcoinlimits_enable + then + eval $(/usr/bin/limits ${bitcoinlimits_args}) 2>/dev/null + else + return 0 + fi +} + +bitcoin_testnet_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 +} + +bitcoin_testnet_start() +{ + echo "Starting bitcoin:" + cd "${bitcoin_testnet_data_dir}" || return 1 + ${daemon_command} \ + -u "${bitcoin_testnet_user}" \ + -l "${bitcoin_testnet_syslog_facility}" \ + -s "${bitcoin_testnet_syslog_priority}" \ + -T "${bitcoin_testnet_syslog_tag}" \ + ${command} \ + -testnet \ + -printtoconsole=1 \ + -conf="${bitcoin_testnet_config_file}" \ + -datadir="${bitcoin_testnet_data_dir}" +} + +bitcoin_testnet_stop() +{ + echo "Stopping bitcoin:" + pid=$(check_pidfile "${pidfile}" "${procname}") + if [ -z "${pid}" ] + then + echo "Bitcoind is not running" + return 1 + else + kill ${pid} + fi +} + +bitcoin_testnet_wait() +{ + local n="${bitcoin_testnet_kill_after}" + echo "Waiting for bitcoin 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"