Instead of being outdoors I geeked out indoors this weekend and amongst other things installed a Bitcoin daemon on a public facing server so I could have a play with the API/RPC features.
Below I document the steps I followed as it turned out to be slightly more taxing than the usual apt-get install bitcoind
Step 1) Get server
This is obviously optional depending on where it’s going but as I wanted it on a public facing machine and I’ve got a few projects where I need to using it soon I installed a new Debian image on the Rackspace cloud.
The newest version of Debian is ‘squeeze’ so I chose that and as for now this is for testing I chose the cheapest instance, 256MB RAM/10GB space for 24p a day (!) but can change this later if I need more grunt.
Step 2) apt-get install fail
It turns out that bitcoind isn’t in the standard package list for squeeze so you need to install it via back-ports. To do so add the following to your /etc/apt/sources.list
deb http://backports.debian.org/debian-backports squeeze-backports main contrib deb-src http://backports.debian.org/debian-backports squeeze-backports main contrib
Save, then run:
apt-get update apt-get install bitcoind
Step 3 ) Install start-up & config scripts
Again, surprisingly for a debian package, there’s no start-up or config installed for you. So you’re going to have to do it yourself.
I took the
script found on this forum and edited it as per the thread recommendations with a few tiny mods of my own:
#! /bin/sh
### BEGIN INIT INFO
# Provides: bitcoind
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: bitcoind daemon startup script
# Description: bitcoind daemon startup script
### END INIT INFO
# Author: Pavel A. Karoukin
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="BitCoin Daemon"
NAME=bitcoind
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
CHUID=user:group
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --chuid $CHUID --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/serv
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
$DAEMON stop
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
Note: items in the script above that may (or will definitely) need changing depending upon your environment are in bold.
Save it as /etc/init.d/bitcoind then run:
chmod +x /etc/init.d/bitcoind update-rc.d bitcoind defaults
Now you need a config file, I got an example one here. Paste it into /home/[user script will run as]/.bitcoin/bitcoin.conf
# bitcoin.conf configuration file. Lines beginning with # are comments. # Network-related settings: # Run on the test network instead of the real bitcoin network. #testnet=1
# Connect via a socks4 proxy #proxy=127.0.0.1:9050 # Use as many addnode= settings as you like to connect to specific peers #addnode=69.164.218.197 #addnode=10.0.0.2:8333 # . or use as many connect= settings as you like to connect ONLY # to specific peers: #connect=69.164.218.197 #connect=10.0.0.1:8333
# Do not use Internet Relay Chat (irc.lfnet.org #bitcoin channel) to # find other peers. #noirc=1
# Maximum number of inbound+outbound connections. #maxconnections= # JSON-RPC options (for controlling a running Bitcoin/bitcoind process) # server=1 tells Bitcoin to accept JSON-RPC commands. #server=1
# You must set rpcuser and rpcpassword to secure the JSON-RPC api #rpcuser=foo #rpcpassword=bar
# How many seconds bitcoin will wait for a complete RPC HTTP request. # after the HTTP connection is established. rpctimeout=30
# By default, only RPC connections from localhost are allowed. Specify # as many rpcallowip= settings as you like to allow connections from # other hosts (and you may use * as a wildcard character): #rpcallowip=10.1.1.34 #rpcallowip=192.168.1.* # Listen for RPC connections on this TCP port: rpcport=8332 # You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind # running on another host using this option: rpcconnect=127.0.0.1
# Use Secure Sockets Layer (also known as TLS or HTTPS) to communicate # with Bitcoin -server or bitcoind #rpcssl=1 # OpenSSL settings used when rpcssl=1 rpcsslciphers=TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH rpcsslcertificatechainfile=server.cert rpcsslprivatekeyfile=server.pem
# Miscellaneous options # Set gen=1 to attempt to generate bitcoins gen=0
# Use SSE instructions to try to generate bitcoins faster. For muliple core processors. #4way=1 # Pre-generate this many public/private key pairs, so wallet backups will be valid for # both prior transactions and several dozen future transactions. keypool=100 # Pay an optional transaction fee every time you send bitcoins. Transactions with fees # are more likely than free transactions to be included in generated blocks, so may # be validated sooner. paytxfee=0.00
# Allow direct connections for the .pay via IP address. feature. #allowreceivebyip=1 # User interface options # Start Bitcoin minimized #min=1
# Minimize to the system tray #minimizetotray=1
4) Run
You can just run the init.d script now, but to be 100% sure that it’ll start on boot I simply rebooted.
On startup I could see a bitcoind process running and in my ~/.bitcoin/ folder I ran
watch ls -alh
I could see these two files slowly increasing in size, as the complete block chain was being synchronised:
-rw------- 1 bealers bealers 151M Jan 22 10:36 blk0001.dat -rw------- 1 bealers bealers 90M Jan 22 10:36 blkindex.dat
You can get more info by running:
bitcoind getinfo
{
"version" : 32400,
"balance" : 0.00000000,
"blocks" : 135450,
"connections" : 114,
"proxy" : "",
"generate" : false,
"genproclimit" : -1,
"difficulty" : 1563027.99611622,
"hashespersec" : 0,
"testnet" : false,
"keypoololdest" : 1327245731,
"paytxfee" : 0.00000000,
"errors" : ""
}
From this I could see that blocks was under the current count.
If you would like to install a more recent version, you can get the latest stable from the bitcoin Ubuntu PPA by using:
deb http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu maverick main
deb-src http://ppa.launchpad.net/bitcoin/bitcoin/ubuntu maverick main
As far as i can tell right now, the required Squeeze libraries match the ones from Maverick.
Cheers,
Raoul
Don’t you need to set this to ’1′ ?
> # Set gen=1 to attempt to generate bitcoins
> gen=0
> Don’t you need to set this to ’1′ ?
Only if you are a miner. On a normal root server I would never set this to 1.
Only if you want to cpu-mine on the rackspace node, which would be a waste of resources.
I was going to say the same thing …