summaryrefslogtreecommitdiff
path: root/net-p2p/monero-cli/files/monerod.in
blob: cf2cf3bee4b17bc304c368a0522df4863a0bf8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
# $FreeBSD$

# PROVIDE: monerod
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

# Add the following to %%LOCALBASE%%/etc/rc.conf.d/monerod to influence
# the behavior of this script (default values are listed):
#
# monerod_enable="NO"  # change to "YES" to enable
# monerod_user="monero"
# monerod_group="monero"
# monerod_data_dir="/var/db/monero"
# monerod_conf="%%PREFIX%%/etc/monerod.conf"
# monerod_log="/var/log/monero.log"
# monerod_bind_addr="0.0.0.0"
# monerod_bind_port="18080"
# monerod_mine_for=""    # Do mining for the given address (empty: no mining)
# monerod_mine_threads=""
# monerod_mine_max_cpu_pct=""
# monerod_extra_args=""  # See monerod --help

. /etc/rc.subr

name="monerod"
rcvar=monerod_enable

load_rc_config ${name}

: ${monerod_enable:="NO"}
: ${monerod_user:="monero"}
: ${monerod_group:="monero"}
: ${monerod_data_dir:="/var/db/monero"}
: ${monerod_conf:="%%PREFIX%%/etc/${name}.conf"}
: ${monerod_log:="/var/log/${name}.log"}
: ${monerod_bind_addr:="0.0.0.0"}
: ${monerod_bind_port:="18080"}

start_precmd="monerod_start_precmd"
pidfile="/var/run/${name}.pid"
command="%%PREFIX%%/bin/monerod"
command_args=""
command_args="${command_args} --data-dir=${monerod_data_dir}"
command_args="${command_args} --detach"
command_args="${command_args} --log-file=${monerod_log}"
command_args="${command_args} --non-interactive"
command_args="${command_args} --p2p-bind-ip=${monerod_bind_addr}"
command_args="${command_args} --p2p-bind-port=${monerod_bind_port}"
command_args="${command_args} --pidfile=${pidfile}"

if [ -e "${monerod_conf}" ] ; then
	command_args="${command_args} --config-file=${monerod_conf}"
fi

if [ -n "${monerod_mine_for}" ] ; then
	a="--bg-mining-enable --start-mining=${monerod_mine_for}"

	if [ -n "${monerod_mine_threads}" ] ; then
		a="${a} --mining-threads=${monerod_mine_threads}"
	fi

	if [ -n "${monerod_mine_max_cpu_pct}" ] ; then
		a="${a} --bg-mining-miner-target=${monerod_mine_max_cpu_pct}"
	fi

	command_args="${command_args} ${a}"
fi

command_args="${command_args} ${monerod_extra_args}"
command_args="${command_args} >${monerod_data_dir}/monerod.stdout"
command_args="${command_args} 2>${monerod_data_dir}/monerod.stderr"

monerod_start_precmd()
{
	if [ ! -e "${pidfile}" ]; then
		install -o ${monerod_user} -g ${monerod_group} -m 644 /dev/null "${pidfile}"
	fi

	if [ ! -e "${monerod_log}" ]; then
		install -o ${monerod_user} -g ${monerod_group} -m 600 /dev/null "${monerod_log}"
	fi

	if [ ! -d "${monerod_data_dir}" ]; then
		install -d -o ${monerod_user} -g ${monerod_group} -m 700 "${monerod_data_dir}"
	fi

	cd "${monerod_data_dir}"
}

run_rc_command "$1"