Mar 172013
 

Thank GNUtransfer the loan us a VPS and other resources to write this article.

In this post we present a script to run automatically in the background bitcoind at system startup, the script is here bitcoin-init-0.1.0.tar.bz2

This script works in Debian Squeezy, Debian Wheezy and Ubuntu Precise Pangolin maybe also in other versions but we have not tested.
NOTE: Works with bitcoind 0.6.x, 0.7.x and 0.8.x recommend version 0.8.x can see our previous articles on how to install it on Debian How to install bitcoin 0.8.0 on debian squeeze amd64 How to install bitcoin 0.8.0 on debian wheezy amd64 and Ubuntu install instructions are here

Now if we start with the installation of the script.

First download the script

root@x252:/tmp# wget http://downloads.geeklab.com.ar/files/scripts/bitcoin-init-0.1.0.tar.bz2
--2013-03-17 20:43:17--  http://downloads.geeklab.com.ar/files/scripts/bitcoin-init-0.1.0.tar.bz2
Resolving downloads.geeklab.com.ar (downloads.geeklab.com.ar)... 69.61.29.79
Connecting to downloads.geeklab.com.ar (downloads.geeklab.com.ar)|69.61.29.79|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4308 (4.2K) [application/x-bzip2]
Saving to: `bitcoin-init-0.1.0.tar.bz2'

100%[=====================================================================================================================================================================================================================================================================================>] 4,308       --.-K/s   in 0s      

2013-03-17 20:43:17 (62.4 MB/s) - `bitcoin-init-0.1.0.tar.bz2' saved [4308/4308]

root@x252:/tmp# 

Then decompress it and entered in the directory bitcoin-init-0.1.0

root@x252:/tmp# tar xjf bitcoin-init-0.1.0.tar.bz2 
root@x252:/tmp# cd bitcoin-init-0.1.0
root@x252:/tmp/bitcoin-init-0.1.0# 

We can see that there is a script called install-bitcoin-init.sh the script is ready to run I install dependencies, create a user for the daemon, copy the files in the system and configure the script, if you want you can edit and modify these variables

SYSTEM_USER=bitcoin 
RPC_USER=bitcoin
##SSL CERT DATA
DAYS=3650
COUNTRYNAME=AR ##2 letter code
STATEORPROVINCENAME="BUENOS AIRES"
LOCALITYNAME=CABA
ORGANITATIONNAME=GeekLab
ORGANITATIONALUNITNAME=GeekLab
COMMONNAME=geeklab.com.ar
EMAILADDRESS=rmalvarez@gnupanel.org
FILE_PEM=bitcoin-init.pem
FILE_CERT=bitcoin-init.cert

The variables are whether to edit

##SSL CERT DATA
COUNTRYNAME=AR ##2 letter code
STATEORPROVINCENAME="BUENOS AIRES"
LOCALITYNAME=CABA
ORGANITATIONNAME=GeekLab
ORGANITATIONALUNITNAME=GeekLab
COMMONNAME=geeklab.com.ar
EMAILADDRESS=rmalvarez@gnupanel.org

The script will do the following

1 – Install dependencies

2 – Create a user and the home will put in /var/lib/${SYSTEM_USER} default /var/lib/bitcoin

3 – Then create the ${SYSTEM_USER_DIR}/.bitcoin default /var/lib/bitcoin/.bitcoin

4 – Copy files bitcoin-server.conf and bitcoin.conf in ${SYSTEM_USER_DIR}/.bitcoin

5 – Replace the variables needed in bitcoin-server.conf and bitcoin.conf rpc password generated at the time it

6 – Copy bitcoin-init file in /etc/default

7 – copy bitcoin-init.sh in /usr/local/bin

8 – Create the symbolic link /etc/init.d/bitcoin-init.sh pointing to /usr/local/bin/bitcoin-init.sh

9 – Create System-V links to the start

10 – Create the SSL certificate for bitcoind

11 – Copy certified in ${SYSTEM_USER_DIR}/.bitcoin default /var/lib/bitcoin/.bitcoin

12 – Accommodate permissions

Now run the script output should be similar to the following

root@x252:/tmp/bitcoin-init-0.1.0# ./install-bitcoin-init.sh 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
coreutils is already the newest version.
openssl is already the newest version.
pwgen is already the newest version.
rpl is already the newest version.
passwd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Replacing __SYSTEM_USER_DIR__ with /var/lib/bitcoin (case sensitive) (partial words matched)
.
A Total of 3 matches replaced in 1 file searched.
Replacing __SYSTEM_USER__ with bitcoin (case sensitive) (partial words matched)
.
A Total of 2 matches replaced in 1 file searched.
Replacing __BITCOIN_RPC_USER__ with bitcoin (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __BITCOIN_RPC_PASSWORD__ with YOUR_SECRET (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __FILE_PEM__ with bitcoin-init.pem (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __FILE_CERT__ with bitcoin-init.cert (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __BITCOIN_RPC_USER__ with bitcoin (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __BITCOIN_RPC_PASSWORD__ with YOUR_SECRET (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
update-rc.d: using dependency based boot sequencing
Replacing __COUNTRY__ with AR (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __STATE__ with BUENOS AIRES (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __LOCALITY__ with CABA (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __ORGANITATION__ with GeekLab (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __ORGANITATION_UNIT__ with GeekLab (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __COMMON_NAME__ with geeklab.com.ar (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Replacing __EMAIL__ with rmalvarez@gnupanel.org (case sensitive) (partial words matched)
.
A Total of 1 matches replaced in 1 file searched.
Generating RSA private key, 4096 bit long modulus
.........................................++
......................................................................++
e is 65537 (0x10001)
root@x252:/tmp/bitcoin-init-0.1.0# 

If you have a bitcoin wallet should copy to /var/lib/bitcoin/.bitcoin

root@x252:/tmp/bitcoin-init-0.1.0# cp wallet.dat /var/lib/bitcoin/.bitcoin
root@x252:/tmp/bitcoin-init-0.1.0# chown bitcoin:bitcoin /var/lib/bitcoin/.bitcoin/wallet.dat 
root@x252:/tmp/bitcoin-init-0.1.0# chmod 0600 /var/lib/bitcoin/.bitcoin/wallet.dat
root@x252:/tmp/bitcoin-init-0.1.0# 

We now proceed to start the daemon.

root@x252:/tmp/bitcoin-init-0.1.0# /etc/init.d/bitcoin-init.sh start
[ ok ] bitcoin-init.sh: Start bitcoind.
root@x252:/tmp/bitcoin-init-0.1.0# 

Wait a few minutes and try to connect to RPC for that we became the bitcoin user and execute a query

root@x252:/tmp/bitcoin-init-0.1.0# su bitcoin
bitcoin@x252:/tmp/bitcoin-init-0.1.0$ bitcoind getinfo
{
    "version" : 80000,
    "protocolversion" : 70001,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 55450,
    "connections" : 9,
    "proxy" : "",
    "difficulty" : 12.84918315,
    "testnet" : false,
    "keypoololdest" : 1363538621,
    "keypoolsize" : 1025,
    "paytxfee" : 0.00000000,
    "errors" : "";
}
bitcoin@x252:/tmp/bitcoin-init-0.1.0$ 

If you want to connect with other users can do the following (example with the user rmalvarez)

root@x252:/tmp/bitcoin-init-0.1.0# mkdir -p /home/rmalvarez/.bitcoin
root@x252:/tmp/bitcoin-init-0.1.0# cp /var/lib/bitcoin/.bitcoin/bitcoin.conf /home/rmalvarez/.bitcoin
root@x252:/tmp/bitcoin-init-0.1.0# chown -R rmalvarez:rmalvarez /home/rmalvarez/.bitcoin
root@x252:/tmp/bitcoin-init-0.1.0# chmod 0600 /home/rmalvarez/.bitcoin/bitcoin.conf 
root@x252:/tmp/bitcoin-init-0.1.0# 

Then try to connect with that user

root@x252:/tmp/bitcoin-init-0.1.0# su rmalvarez
rmalvarez@x252:/tmp/bitcoin-init-0.1.0$ bitcoind getinfo  
{
    "version" : 80000,
    "protocolversion" : 70001,
    "walletversion" : 60000,
    "balance" : 0.00000000,
    "blocks" : 88932,
    "connections" : 8,
    "proxy" : "",
    "difficulty" : 3091.73689041,
    "testnet" : false,
    "keypoololdest" : 1363538621,
    "keypoolsize" : 1025,
    "paytxfee" : 0.00000000,
    "errors" : "";
}
rmalvarez@x252:/tmp/bitcoin-init-0.1.0$ 

They can check the script to see detail the steps that meets your needs.

Keep in mind that bitcoin database updated to be long in some cases more than two days.

Bitcoin 0.8.x accept RPC connections even without the database updated (a few minutes into the first) in the case of versions 0.7.x and 0.6.x RPC not accept connections until you have fully updated base

Any bug or misconception feel free to leave a comment.

This concludes this article