Bitcoin Forum
October 19, 2017, 06:29:06 PM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: How to start Bitcoind on ubuntu startup  (Read 3369 times)
cshelswell
Hero Member
*****
Offline Offline

Activity: 582


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

1508437746
Hero Member
*
Offline Offline

Posts: 1508437746

View Profile Personal Message (Offline)

Ignore
1508437746
Reply with quote  #2

1508437746
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1508437746
Hero Member
*
Offline Offline

Posts: 1508437746

View Profile Personal Message (Offline)

Ignore
1508437746
Reply with quote  #2

1508437746
Report to moderator
dserrano5
Legendary
*
Offline Offline

Activity: 1848



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

Wolf0
Legendary
*
Online Online

Activity: 1722


Miner Developer


View Profile
October 10, 2013, 08:50:21 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?

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

Throw bitcoind in your /etc/rc.local.

Code:
Donations: BTC: 1WoLFdwcfNEg64fTYsX1P25KUzzSjtEZC -- XMR: 45SLUTzk7UXYHmzJ7bFN6FPfzTusdUVAZjPRgmEDw7G3SeimWM2kCdnDQXwDBYGUWaBtZNgjYtEYA22aMQT4t8KfU3vHLHG
redtwitz
Full Member
***
Offline Offline

Activity: 231


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

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
Hero Member
*****
Offline Offline

Activity: 582


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

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


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

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
Hero Member
*****
Offline Offline

Activity: 582


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

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


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

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

Activity: 582


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

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: 1848



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

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


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

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
Hero Member
*****
Offline Offline

Activity: 582


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

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


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

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

Activity: 582


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

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


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

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
Hero Member
*****
Offline Offline

Activity: 582


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

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


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

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

Activity: 239



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

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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!