blob: 2d1e25e79f30f8941da9a5b9518b722f59daa1ef (
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
92
93
94
95
96
97
98
99
100
|
#!/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"
|