Document assumptions that are being made to avoid division by zero
[bitcoinplatinum.git] / contrib / init / bitcoind.openrc
blob50377c09957c0d087681365470f9852581296310
1 #!/sbin/runscript
3 # backward compatibility for existing gentoo layout 
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
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}}"
21 name="Bitcoin Core Daemon"
22 description="Bitcoin cryptocurrency P2P network daemon"
24 command="/usr/bin/bitcoind"
25 command_args="-pid=\"${BITCOIND_PIDFILE}\" \
26                 -conf=\"${BITCOIND_CONFIGFILE}\" \
27                 -datadir=\"${BITCOIND_DATADIR}\" \
28                 -daemon \
29                 ${BITCOIND_OPTS}"
31 required_files="${BITCOIND_CONFIGFILE}"
32 start_stop_daemon_args="-u ${BITCOIND_USER} \
33                         -N ${BITCOIND_NICE} -w 2000"
34 pidfile="${BITCOIND_PIDFILE}"
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}"
41 depend() {
42         need localmount net
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}"
56         checkpath \
57         -d \
58         --mode 0755 \
59         --owner "${BITCOIND_USER}:${BITCOIND_GROUP}" \
60         "${BITCOIND_PIDDIR}"
62         checkpath -f \
63         -o ${BITCOIND_USER}:${BITCOIND_GROUP} \
64         -m 0660 \
65         ${BITCOIND_CONFIGFILE}
67         checkconfig || return 1
70 checkconfig()
72         if ! grep -qs '^rpcpassword=' "${BITCOIND_CONFIGFILE}" ; then
73                 eerror ""
74                 eerror "ERROR: You must set a secure rpcpassword to run bitcoind."
75                 eerror "The setting must appear in ${BITCOIND_CONFIGFILE}"
76                 eerror ""
77                 eerror "This password is security critical to securing wallets "
78                 eerror "and must not be the same as the rpcuser setting."
79                 eerror "You can generate a suitable random password using the following "
80                 eerror "command from the shell:"
81                 eerror ""
82                 eerror "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'"
83                 eerror ""
84                 eerror "It is recommended that you also set alertnotify so you are "
85                 eerror "notified of problems:"
86                 eerror ""
87                 eerror "ie: alertnotify=echo %%s | mail -s \"Bitcoin Alert\"" \
88                         "admin@foo.com"
89                 eerror ""
90                 return 1
91         fi