Bitcoin Forum
April 26, 2024, 10:46:25 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to start Bitcoind on ubuntu startup  (Read 3746 times)
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 10, 2013, 08:28:15 PM
 #1

Hi I've got bitcoind installed on a headless ubuntu server to run an application. I'm just trying to get it to start on a reboot. I've had a really good search and can't find anything that I think is applicable to me. I found this: https://bitcointalk.org/?topic=965.0 but I installed bitcoin from the PPA's and there's nothing in the /etc/init.d folder. Can i just go ahead and create this script anyway?

Any advice on how to get ubuntu to load bitcoind at startup would be great - thanks Smiley

1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
"In a nutshell, the network works like a distributed timestamp server, stamping the first transaction to spend a coin. It takes advantage of the nature of information being easy to spread but hard to stifle." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
1714128385
Hero Member
*
Offline Offline

Posts: 1714128385

View Profile Personal Message (Offline)

Ignore
1714128385
Reply with quote  #2

1714128385
Report to moderator
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
October 10, 2013, 08:42:03 PM
 #2

Not the most professional in the world but this is what I have:

Code:
$ grep bitcoin /etc/crontab
@reboot         btc     /usr/bin/nice /home/btc/bin/bitcoind
redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 10, 2013, 08:59:31 PM
 #3

Hi I've got bitcoind installed on a headless ubuntu server to run an application. I'm just trying to get it to start on a reboot. I've had a really good search and can't find anything that I think is applicable to me. I found this: https://bitcointalk.org/?topic=965.0 but I installed bitcoin from the PPA's and there's nothing in the /etc/init.d folder. Can i just go ahead and create this script anyway?

Init scripts will work, no matter where the executables came from. However, they are a hassle.

Throw bitcoind in your /etc/rc.local.

If you do, be careful to execute the daemon as the proper user.

On Ubuntu, the file exists by default, so adding the line

Code:
su cshelswell -c bitcoind

anywhere before the exit command should do the job.
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 10, 2013, 09:18:22 PM
 #4

hey guys - thanks for your help. I think i might be missing something though as I'm not getting it working. So i've edited /etc/rc.local and added the line:

Code:
su myuser -c bitcoind

rebooted but a bitcoind getinfo get's "couldn't connect to server"?  I'm guessing I'm missing a step somewhere?

Thanks for you help Smiley

redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 10, 2013, 09:23:55 PM
 #5

As long as myuser is a login account and bitcoind is in myuser's path, that should work (although I forgot the ampersand at the end). It should be

Code:
su myuser -c bitcoind &

Check that /etc/rc.local is executable. If it is and it still doesn't work, could you post its entire contents?
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 10, 2013, 09:34:14 PM
 #6

hmm still not working. I'm assuming that bitcoind is in the path since all i have to do to start it is type "bitcoind"

thanks

redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 10, 2013, 09:36:38 PM
 #7

What else does /etc/rc.local contain? Is it executable? What haapens if you execute sudo /etc/rc.local from a terminal?
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 10, 2013, 09:51:28 PM
 #8

hey so /etc/rc.local contains:

Code:
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
myuser -c bitcoind &
exit 0

if i run it as root it just does nothing. Doesn't load bitcoind which i'm assuming it should?

dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
October 10, 2013, 10:05:46 PM
 #9

Specify the full path. The environment on rc.local doesn't necessarily matches the one on that user's shell. That includes $PATH.

And "su" is missing there.
redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 10, 2013, 10:06:38 PM
 #10

I see no shebang. The first line should say something like this:

Code:
#!/bin/sh -e

If "sh -e" is indeed being used, the second command won't be executed if the first one fails. To avoid this, change the first command to

Code:
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server || :

or the shebang to

Code:
#!/bin/sh

Also, the second command seems to be missing the "su" at the beginning.

Specify the full path. The environment on rc.local doesn't necessarily matches the one on that user's shell. That includes $PATH.

Right. Without the "-l" switch, root's path would be used. But if "sudo /etc/rc.local" doesn't complain about a missing executable, so something else is (also) wrong.
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 10, 2013, 10:12:20 PM
 #11

sorry the whole file is:

Code:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
su myuser -c bitcoind &
exit 0

though if i run it now i just get: mkdir: cannot create directory ‘/home/myuser/.bitcoin’: No such file or directory

I installed bitcoind as root could that be the issue?

thanks for all your help!


redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 10, 2013, 11:35:04 PM
 #12

Does the directory /home/myuser exist? What happens if you login as myuser and execute bitcoind?
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 11, 2013, 12:40:15 AM
 #13

yeah that doesn't work. Is there no way to run /etc/rc.local as root and have:

Code:
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
root -c bitcoind &
exit 0

Cheers

redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 11, 2013, 02:08:21 AM
 #14

Of course you can run bitcoind as root, although by the principle of least privilege, you shouldn't.

In this case, the command would be just

Code:
bitcoind -daemon

since rc.local gets executed by root anyway (the "-daemon" switch seems more natural than the ampersand).

However, it looks like myuser doesn't have a hoe directory. This would be the case if you, e.g., created it with

Code:
useradd myuser

If you have already configured bitcoind as root (created a configuration file, downloaded the blockchain, etc.), do the following as root:

Code:
mkdir /home/myuser
mv /root/.bitcoin /home/myuser
chown -R myuser:myuser /home/myuser

If not, do the following as root:

Code:
mkdir -p /home/myuser/.bitcoin
echo -n rpcpassword= > /home/myuser/.bitcoin/bitcoin.conf
head -c 16 /dev/random | md5sum | cut -b 1-32 >> /home/myuser/.bitcoin/bitcoin.conf
echo daemon=1 >> /home/myuser/.bitcoin/bitcoin.conf
chown -R myuser:myuser /home/myuser
chmod 600 /home/myuser/.bitcoin/bitcoin.conf

The setting "daemon=1" makes the ampersand obsolete.
cshelswell (OP)
Hero Member
*****
Offline Offline

Activity: 615
Merit: 500


View Profile WWW
October 11, 2013, 06:00:02 AM
 #15

Finally solved it with your help - thank you!! It seems that rc.local was all good. What wasn't good was that ubuntu wasn't running it on boot. I followed the instructions on this site http://askubuntu.com/questions/299792/why-is-the-command-in-etc-rc-local-not-executed-during-startup

and had to
Code:
 apt-get install sysv-rc-conf
then run sudo sysv-rc-conf after that after a reboot one wonderful instance of bitcoind running Smiley

Thanks so so much for all your help!!!

redtwitz
Full Member
***
Offline Offline

Activity: 231
Merit: 100


View Profile
October 11, 2013, 11:50:47 AM
 #16

Glad you got it working. Smiley
vindimy
Full Member
***
Offline Offline

Activity: 239
Merit: 100



View Profile
October 13, 2013, 05:59:56 AM
 #17

If you guys want a really easy and fast way to install and manage bitcoind (or any other altcoin) and keep it up to date, consider the Opscode Chef crypto-coin cookbook.

I use it for my "altcointip bot" project. It provides automated, zero-config install of any coin by compiling specific release from source. It uses upstart to control the coin service:

Code:
: ~$ cat /etc/init/bitcoind.conf
description bitcoind

start on runlevel [2345]
stop on runlevel [016]

setuid bitcoin
setgid altcointip

respawn
respawn limit 10 60 # 10 times in 60 seconds

exec /opt/altcointip/coins/bitcoin/bitcoind -datadir=/opt/altcointip/coins/bitcoin/data -conf=/opt/altcointip/coins/bitcoin/bitcoin.conf

Here's what final result looks like:

Code:
:~$ ps aux|grep coin
litecoin   664  0.4  9.3 1667632 190036 ?      SLsl Oct07  37:50 /opt/altcointip/coins/litecoin/litecoind -datadir=/opt/altcointip/coins/litecoin/data -conf=/opt/altcointip/coins/litecoin/litecoin.conf
ppcoin     668  0.3  3.0 867176 62248 ?        Ssl  Oct07  26:14 /opt/altcointip/coins/ppcoin/ppcoind -datadir=/opt/altcointip/coins/ppcoin/data -conf=/opt/altcointip/coins/ppcoin/ppcoin.conf
2007       673  0.4  4.5 1447688 93268 ?       SLsl Oct07  35:19 /opt/altcointip/coins/primecoin/primecoind -datadir=/opt/altcointip/coins/primecoin/data -conf=/opt/altcointip/coins/primecoin/primecoin.conf
bitcoin    676  0.7 17.1 1812184 350156 ?      SLsl Oct07  65:57 /opt/altcointip/coins/bitcoin/bitcoind -datadir=/opt/altcointip/coins/bitcoin/data -conf=/opt/altcointip/coins/bitcoin/bitcoin.conf
namecoin   680  0.2 10.9 834768 223228 ?       Ssl  Oct07  25:06 /opt/altcointip/coins/namecoin/namecoind -datadir=/opt/altcointip/coins/namecoin/data -conf=/opt/altcointip/coins/namecoin/namecoin.conf
2009      3526  0.6  4.4 917764 90960 ?        Ssl  Oct07  47:59 /opt/altcointip/coins/feathercoin/feathercoind -datadir=/opt/altcointip/coins/feathercoin/data -conf=/opt/altcointip/coins/feathercoin/feathercoin.conf

:~$ bitcoind getinfo
{
    "version" : 80500,
    "protocolversion" : 70001,
    "walletversion" : 60000,
    "balance" : 0.68225642,
    "blocks" : 263287,
    "timeoffset" : -10,
    "connections" : 10,
    "proxy" : "",
    "difficulty" : 189281249.28103292,
    "testnet" : false,
    "keypoololdest" : 1376917621,
    "keypoolsize" : 100,
    "paytxfee" : 0.00010000,
    "unlocked_until" : 0,
    "errors" : ""
}

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!