Line 0
Link Here
|
|
|
1 |
#!/bin/sh |
2 |
# $FreeBSD$ |
3 |
|
4 |
# PROVIDE: blackcoind |
5 |
# REQUIRE: LOGIN cleanvar |
6 |
# KEYWORD: shutdown |
7 |
|
8 |
# |
9 |
# Add the following lines to /etc/rc.conf to enable : |
10 |
# blackcoind_enable (bool): Set to "NO" by default. |
11 |
# Set it to "YES" to enable blackcoind |
12 |
# blackcoind_user (str) Set to "blackcoin" by default. |
13 |
# blackcoind_group (str) Set to "blackcoin" by default. |
14 |
# blackcoind_conf (str) Set to "%%PREFIX%%/etc/blackcoind.conf" by default. |
15 |
# blackcoind_data_dir (str) Set to "/var/db/blackcoin" by default. |
16 |
# blackcoindlimits_enable (bool) Set to "NO" by default. |
17 |
# Set it to "YES" to enable blackcoindlimits |
18 |
# blackcoindlimits_args Set to "-e -U ${blackcoind_user}" by default |
19 |
|
20 |
|
21 |
. /etc/rc.subr |
22 |
|
23 |
name="blackcoind" |
24 |
rcvar=blackcoind_enable |
25 |
|
26 |
start_precmd="blackcoind_precmd" |
27 |
start_cmd="blackcoind_start" |
28 |
restart_precmd="blackcoind_checkconfig" |
29 |
reload_precmd="blackcoind_checkconfig" |
30 |
configtest_cmd="blackcoind_checkconfig" |
31 |
status_cmd="blackcoind_status" |
32 |
stop_cmd="blackcoind_stop" |
33 |
stop_postcmd="blackcoind_wait" |
34 |
command="%%PREFIX%%/bin/blackcoind" |
35 |
daemon_command="/usr/sbin/daemon" |
36 |
extra_commands="configtest" |
37 |
|
38 |
|
39 |
: ${blackcoind_enable:="NO"} |
40 |
: ${blackcoindlimits_enable:="NO"} |
41 |
|
42 |
load_rc_config ${name} |
43 |
|
44 |
: ${blackcoind_user:="blackcoin"} |
45 |
: ${blackcoind_group:="blackcoin"} |
46 |
: ${blackcoind_data_dir:="/var/db/blackcoin"} |
47 |
: ${blackcoind_config_file:="%%PREFIX%%/etc/blackcoin.conf"} |
48 |
: ${blackcoindlimits_args:="-e -U ${blackcoind_user}"} |
49 |
|
50 |
# set up dependant variables |
51 |
procname="${command}" |
52 |
pidfile="${blackcoind_data_dir}/blackcoind.pid" |
53 |
required_files="${blackcoind_config_file}" |
54 |
|
55 |
blackcoind_checkconfig() |
56 |
{ |
57 |
echo "Performing sanity check on blackcoind configuration:" |
58 |
if [ ! -d "${blackcoind_data_dir}" ] |
59 |
then |
60 |
echo "Missing data directory: ${blackcoind_data_dir}" |
61 |
exit 1 |
62 |
fi |
63 |
|
64 |
if [ ! -f "${blackcoind_config_file}" ] |
65 |
then |
66 |
echo "Missing configuration file: ${blackcoind_config_file}" |
67 |
exit 1 |
68 |
fi |
69 |
if [ ! -x "${command}" ] |
70 |
then |
71 |
echo "Missing executable: ${command}" |
72 |
exit 1 |
73 |
fi |
74 |
return 0 |
75 |
} |
76 |
|
77 |
blackcoind_cleanup() |
78 |
{ |
79 |
rm -f "${pidfile}" |
80 |
} |
81 |
|
82 |
blackcoind_precmd() |
83 |
{ |
84 |
blackcoind_checkconfig |
85 |
|
86 |
pid=$(check_pidfile "${pidfile}" "${procname}") |
87 |
if [ -z "${pid}" ] |
88 |
then |
89 |
echo "blackcoind is not running" |
90 |
rm -f "${pidfile}" |
91 |
fi |
92 |
|
93 |
if checkyesno blackcoindlimits_enable |
94 |
then |
95 |
eval $(/usr/bin/limits ${blackcoindlimits_args}) 2>/dev/null |
96 |
else |
97 |
return 0 |
98 |
fi |
99 |
} |
100 |
|
101 |
blackcoind_status() |
102 |
{ |
103 |
local pid |
104 |
pid=$(check_pidfile "${pidfile}" "${procname}") |
105 |
if [ -z "${pid}" ] |
106 |
then |
107 |
echo "blackcoind is not running" |
108 |
return 1 |
109 |
else |
110 |
echo "blackcoind running, pid: ${pid}" |
111 |
fi |
112 |
} |
113 |
|
114 |
blackcoind_start() |
115 |
{ |
116 |
echo "Starting blackcoind:" |
117 |
cd "${blackcoind_data_dir}" || return 1 |
118 |
${daemon_command} -u "${blackcoind_user}" -p "${pidfile}" \ |
119 |
${command} \ |
120 |
-conf="${blackcoind_config_file}" \ |
121 |
-datadir="${blackcoind_data_dir}" \ |
122 |
2> "${blackcoind_data_dir}/blackcoind.stderr" \ |
123 |
> "${blackcoind_data_dir}/blackcoind.stdout" |
124 |
} |
125 |
|
126 |
blackcoind_stop() |
127 |
{ |
128 |
echo "Stopping blackcoind:" |
129 |
pid=$(check_pidfile "${pidfile}" "${procname}") |
130 |
if [ -z "${pid}" ] |
131 |
then |
132 |
echo "blackcoind is not running" |
133 |
return 1 |
134 |
else |
135 |
kill ${pid} |
136 |
fi |
137 |
} |
138 |
|
139 |
blackcoind_wait() |
140 |
{ |
141 |
local n=60 |
142 |
echo "Waiting for blackcoind shutdown:" |
143 |
while : |
144 |
do |
145 |
printf '.' |
146 |
pid=$(check_pidfile "${pidfile}" "${procname}") |
147 |
if [ -z "${pid}" ] |
148 |
then |
149 |
printf '\n' |
150 |
break |
151 |
fi |
152 |
sleep 1 |
153 |
n=$((${n} - 1)) |
154 |
if [ ${n} -eq 0 -a -f "${pidfile}" ] |
155 |
then |
156 |
printf "\nForce shutdown" |
157 |
kill -9 $(cat "${pidfile}") |
158 |
for n in 1 2 3 |
159 |
do |
160 |
printf '.' |
161 |
sleep 1 |
162 |
done |
163 |
printf '\n' |
164 |
break |
165 |
fi |
166 |
done |
167 |
rm -f "${pidfile}" |
168 |
echo "Shutdown complete" |
169 |
} |
170 |
|
171 |
run_rc_command "$1" |