bitcoind.openrc raw
1 #!/sbin/openrc-run
2
3 # backward compatibility for existing gentoo layout
4 #
5 if [ -d "/var/lib/bitcoin/.bitcoin" ]; then
6 BITCOIND_DEFAULT_DATADIR="/var/lib/bitcoin/.bitcoin"
7 else
8 BITCOIND_DEFAULT_DATADIR="/var/lib/bitcoind"
9 fi
10
11 BITCOIND_CONFIGFILE=${BITCOIND_CONFIGFILE:-/etc/bitcoin/bitcoin.conf}
12 BITCOIND_PIDDIR=${BITCOIND_PIDDIR:-/var/run/bitcoind}
13 BITCOIND_PIDFILE=${BITCOIND_PIDFILE:-${BITCOIND_PIDDIR}/bitcoind.pid}
14 BITCOIND_DATADIR=${BITCOIND_DATADIR:-${BITCOIND_DEFAULT_DATADIR}}
15 BITCOIND_USER=${BITCOIND_USER:-${BITCOIN_USER:-bitcoin}}
16 BITCOIND_GROUP=${BITCOIND_GROUP:-bitcoin}
17 BITCOIND_BIN=${BITCOIND_BIN:-/usr/bin/bitcoind}
18 BITCOIND_NICE=${BITCOIND_NICE:-${NICELEVEL:-0}}
19 BITCOIND_OPTS="${BITCOIND_OPTS:-${BITCOIN_OPTS}}"
20
21 name="Bitcoin Core Daemon"
22 description="Bitcoin cryptocurrency P2P network daemon"
23
24 command="/usr/bin/bitcoind"
25 command_args="-pid=\"${BITCOIND_PIDFILE}\" \
26 -conf=\"${BITCOIND_CONFIGFILE}\" \
27 -datadir=\"${BITCOIND_DATADIR}\" \
28 -daemon \
29 ${BITCOIND_OPTS}"
30
31 required_files="${BITCOIND_CONFIGFILE}"
32 start_stop_daemon_args="-u ${BITCOIND_USER} \
33 -N ${BITCOIND_NICE} -w 2000"
34 pidfile="${BITCOIND_PIDFILE}"
35
36 # The retry schedule to use when stopping the daemon. Could be either
37 # a timeout in seconds or multiple signal/timeout pairs (like
38 # "SIGKILL/180 SIGTERM/300")
39 retry="${BITCOIND_SIGTERM_TIMEOUT}"
40
41 depend() {
42 need localmount net
43 }
44
45 # verify
46 # 1) that the datadir exists and is writable (or create it)
47 # 2) that a directory for the pid exists and is writable
48 # 3) ownership and permissions on the config file
49 start_pre() {
50 checkpath \
51 -d \
52 --mode 0750 \
53 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" \
54 "${BITCOIND_DATADIR}"
55
56 checkpath \
57 -d \
58 --mode 0755 \
59 --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" \
60 "${BITCOIND_PIDDIR}"
61
62 checkpath -f \
63 -o "${BITCOIND_USER}:${BITCOIND_GROUP}" \
64 -m 0660 \
65 "${BITCOIND_CONFIGFILE}"
66
67 checkconfig || return 1
68 }
69
70 checkconfig()
71 {
72 if grep -qs '^rpcuser=' "${BITCOIND_CONFIGFILE}" && \
73 ! grep -qs '^rpcpassword=' "${BITCOIND_CONFIGFILE}" ; then
74 eerror ""
75 eerror "ERROR: You must set a secure rpcpassword to run bitcoind."
76 eerror "The setting must appear in ${BITCOIND_CONFIGFILE}"
77 eerror ""
78 eerror "This password is security critical to securing wallets "
79 eerror "and must not be the same as the rpcuser setting."
80 eerror "You can generate a suitable random password using the following "
81 eerror "command from the shell:"
82 eerror ""
83 eerror "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'"
84 eerror ""
85 eerror "It is recommended that you also set alertnotify so you are "
86 eerror "notified of problems:"
87 eerror ""
88 eerror "ie: alertnotify=echo %%s | mail -s \"Bitcoin Alert\"" \
89 "admin@foo.com"
90 eerror ""
91 return 1
92 fi
93 }
94