summaryrefslogtreecommitdiff
path: root/net-p2p/bitcoin-core/files/26.0-init.patch
blob: d42d44f0642ae58af340035e02f8aeb8f094c0d1 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
From 779e7c8fe188bea5b2185be0784112104be168df Mon Sep 17 00:00:00 2001
From: Matt Whitlock <bitcoin@mattwhitlock.name>
Date: Sun, 17 Sep 2023 10:02:20 -0400
Subject: [PATCH] contrib/init: improve OpenRC scripts and systemd service unit

---
 contrib/init/bitcoind.openrc     | 112 +++++++++++++++----------------
 contrib/init/bitcoind.openrcconf |   7 +-
 contrib/init/bitcoind.service    |   5 ++
 3 files changed, 64 insertions(+), 60 deletions(-)

diff --git a/contrib/init/bitcoind.openrc b/contrib/init/bitcoind.openrc
index 013a1a6070..7d16e975e5 100644
--- a/contrib/init/bitcoind.openrc
+++ b/contrib/init/bitcoind.openrc
@@ -1,76 +1,72 @@
 #!/sbin/openrc-run
 
-# backward compatibility for existing gentoo layout 
-#
-if [ -d "/var/lib/bitcoin/.bitcoin" ]; then
-	BITCOIND_DEFAULT_DATADIR="/var/lib/bitcoin/.bitcoin"
-else
-	BITCOIND_DEFAULT_DATADIR="/var/lib/bitcoind"
-fi
+: ${BITCOIND_CONFIGFILE:=/etc/bitcoin/bitcoin.conf}
+: ${BITCOIND_PIDDIR:=/run/bitcoind}
+: ${BITCOIND_PIDFILE:=${BITCOIND_PIDDIR}/${SVCNAME}.pid}
+: ${BITCOIND_DATADIR:=/var/lib/bitcoind}
+: ${BITCOIND_LOGDIR:=/var/log/bitcoind}
+: ${BITCOIND_USER:=${BITCOIN_USER:-bitcoin}}
+: ${BITCOIND_GROUP:=bitcoin}
+: ${BITCOIND_BIN:=/usr/bin/bitcoind}
+: ${BITCOIND_NICE:=${NICELEVEL:-0}}
+: ${BITCOIND_OPTS=${BITCOIN_OPTS}}
 
-BITCOIND_CONFIGFILE=${BITCOIND_CONFIGFILE:-/etc/bitcoin/bitcoin.conf}
-BITCOIND_PIDDIR=${BITCOIND_PIDDIR:-/var/run/bitcoind}
-BITCOIND_PIDFILE=${BITCOIND_PIDFILE:-${BITCOIND_PIDDIR}/bitcoind.pid}
-BITCOIND_DATADIR=${BITCOIND_DATADIR:-${BITCOIND_DEFAULT_DATADIR}}
-BITCOIND_USER=${BITCOIND_USER:-${BITCOIN_USER:-bitcoin}}
-BITCOIND_GROUP=${BITCOIND_GROUP:-bitcoin}
-BITCOIND_BIN=${BITCOIND_BIN:-/usr/bin/bitcoind}
-BITCOIND_NICE=${BITCOIND_NICE:-${NICELEVEL:-0}}
-BITCOIND_OPTS="${BITCOIND_OPTS:-${BITCOIN_OPTS}}"
-
-name="Bitcoin Core Daemon"
+name="Bitcoin Core daemon"
 description="Bitcoin cryptocurrency P2P network daemon"
 
-command="/usr/bin/bitcoind"
-command_args="-pid=\"${BITCOIND_PIDFILE}\" \
-		-conf=\"${BITCOIND_CONFIGFILE}\" \
-		-datadir=\"${BITCOIND_DATADIR}\" \
-		-daemon \
-		${BITCOIND_OPTS}"
-
 required_files="${BITCOIND_CONFIGFILE}"
-start_stop_daemon_args="-u ${BITCOIND_USER} \
-			-N ${BITCOIND_NICE} -w 2000"
 pidfile="${BITCOIND_PIDFILE}"
-
-# The retry schedule to use when stopping the daemon. Could be either
-# a timeout in seconds or multiple signal/timeout pairs (like
-# "SIGKILL/180 SIGTERM/300")
-retry="${BITCOIND_SIGTERM_TIMEOUT}"
+in_background_fake="start"
 
 depend() {
 	need localmount net
 }
 
-# verify
-# 1) that the datadir exists and is writable (or create it)
-# 2) that a directory for the pid exists and is writable
-# 3) ownership and permissions on the config file
 start_pre() {
-	checkpath \
-	-d \
-	--mode 0750 \
-	--owner "${BITCOIND_USER}:${BITCOIND_GROUP}" \
-	"${BITCOIND_DATADIR}"
-
-	checkpath \
-	-d \
-	--mode 0755 \
-	--owner "${BITCOIND_USER}:${BITCOIND_GROUP}" \
-	"${BITCOIND_PIDDIR}"
-
-	checkpath -f \
-	-o "${BITCOIND_USER}:${BITCOIND_GROUP}" \
-	-m 0660 \
-	"${BITCOIND_CONFIGFILE}"
-
-	checkconfig || return 1
+	checkpath -f --mode 0660 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" "${BITCOIND_CONFIGFILE}"
+	checkpath -d --mode 0750 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" "${BITCOIND_DATADIR}"
+	checkpath -d --mode 0755 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" "${BITCOIND_LOGDIR}"
+	checkpath -d --mode 0755 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" "${BITCOIND_PIDDIR}"
+	checkconfig
 }
 
-checkconfig()
-{
-	if grep -qs '^rpcuser=' "${BITCOIND_CONFIGFILE}" && \
-		! grep -qs '^rpcpassword=' "${BITCOIND_CONFIGFILE}" ; then
+start() {
+	ebegin "Starting ${name}"
+	mark_service_inactive
+	if start-stop-daemon \
+		--pidfile="${BITCOIND_PIDFILE}" \
+		--chdir="${BITCOIND_DATADIR}" \
+		--user="${BITCOIND_USER}:${BITCOIND_GROUP}" \
+		--nice="${BITCOIND_NICE}" \
+		--exec="${BITCOIND_BIN}" \
+		-- \
+		-daemonwait \
+		-pid="${BITCOIND_PIDFILE}" \
+		-conf="${BITCOIND_CONFIGFILE}" \
+		-datadir="${BITCOIND_DATADIR}" \
+		-debuglogfile="${BITCOIND_LOGDIR}/debug.log" \
+		${BITCOIND_OPTS}
+	then
+		chmod g+r "${BITCOIND_DATADIR}/.cookie"
+		IN_BACKGROUND=yes rc-service "${SVCNAME}" --quiet start
+	else
+		rc-service "${SVCNAME}" --quiet zap
+	fi &
+}
+
+stop() {
+	ebegin "Stopping ${name}"
+	start-stop-daemon --stop \
+		--pidfile="${BITCOIND_PIDFILE}" \
+		--retry="${BITCOIND_SIGTERM_TIMEOUT}" \
+		--exec="${BITCOIND_BIN}"
+	eend $?
+}
+
+checkconfig() {
+	if grep -qs '^rpcuser=' "${BITCOIND_CONFIGFILE}" &&
+		! grep -qs '^rpcpassword=' "${BITCOIND_CONFIGFILE}"
+	then
 		eerror ""
 		eerror "ERROR: You must set a secure rpcpassword to run bitcoind."
 		eerror "The setting must appear in ${BITCOIND_CONFIGFILE}"
diff --git a/contrib/init/bitcoind.openrcconf b/contrib/init/bitcoind.openrcconf
index c8a22a08d9..f5a140ab9d 100644
--- a/contrib/init/bitcoind.openrcconf
+++ b/contrib/init/bitcoind.openrcconf
@@ -4,14 +4,17 @@
 #BITCOIND_CONFIGFILE="/etc/bitcoin/bitcoin.conf"
 
 # What directory to write pidfile to?  (created and owned by $BITCOIND_USER)
-#BITCOIND_PIDDIR="/var/run/bitcoind"
+#BITCOIND_PIDDIR="/run/bitcoind"
 
 # What filename to give the pidfile
-#BITCOIND_PIDFILE="${BITCOIND_PIDDIR}/bitcoind.pid"
+#BITCOIND_PIDFILE="${BITCOIND_PIDDIR}/${SVCNAME}.pid"
 
 # Where to write bitcoind data (be mindful that the blockchain is large)
 #BITCOIND_DATADIR="/var/lib/bitcoind"
 
+# Where to write the debug.log file
+#BITCOIND_LOGDIR="/var/log/bitcoind"
+
 # User and group to own bitcoind process
 #BITCOIND_USER="bitcoin"
 #BITCOIND_GROUP="bitcoin"
diff --git a/contrib/init/bitcoind.service b/contrib/init/bitcoind.service
index 87da17f955..e1229f300a 100644
--- a/contrib/init/bitcoind.service
+++ b/contrib/init/bitcoind.service
@@ -20,6 +20,7 @@ Wants=network-online.target
 [Service]
 ExecStart=/usr/bin/bitcoind -pid=/run/bitcoind/bitcoind.pid \
                             -conf=/etc/bitcoin/bitcoin.conf \
+                            -debuglogfile=/var/log/bitcoind/debug.log \
                             -datadir=/var/lib/bitcoind \
                             -startupnotify='systemd-notify --ready' \
                             -shutdownnotify='systemd-notify --stopping'
@@ -54,6 +55,10 @@ RuntimeDirectoryMode=0710
 ConfigurationDirectory=bitcoin
 ConfigurationDirectoryMode=0710
 
+# /var/log/bitcoind
+LogsDirectory=bitcoind
+LogsDirectoryMode=0755
+
 # /var/lib/bitcoind
 StateDirectory=bitcoind
 StateDirectoryMode=0710
-- 
2.43.0