Title: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 10, 2013, 08:28:15 PM 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 (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 :) Title: Re: How to start Bitcoind on ubuntu startup Post by: dserrano5 on October 10, 2013, 08:42:03 PM Not the most professional in the world but this is what I have:
Code: $ grep bitcoin /etc/crontab Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 10, 2013, 08:59:31 PM 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. Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 10, 2013, 09:18:22 PM 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 :) Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 10, 2013, 09:23:55 PM 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? Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 10, 2013, 09:34:14 PM 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 Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 10, 2013, 09:36:38 PM What else does /etc/rc.local contain? Is it executable? What haapens if you execute sudo /etc/rc.local from a terminal?
Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 10, 2013, 09:51:28 PM hey so /etc/rc.local contains:
Code: test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server if i run it as root it just does nothing. Doesn't load bitcoind which i'm assuming it should? Title: Re: How to start Bitcoind on ubuntu startup Post by: dserrano5 on October 10, 2013, 10:05:46 PM 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. Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 10, 2013, 10:06:38 PM 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. Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 10, 2013, 10:12:20 PM sorry the whole file is:
Code: #!/bin/sh -e 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! Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 10, 2013, 11:35:04 PM Does the directory /home/myuser exist? What happens if you login as myuser and execute bitcoind?
Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 11, 2013, 12:40:15 AM 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 Cheers Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 11, 2013, 02:08:21 AM 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 If not, do the following as root: Code: mkdir -p /home/myuser/.bitcoin The setting "daemon=1" makes the ampersand obsolete. Title: Re: How to start Bitcoind on ubuntu startup Post by: cshelswell on October 11, 2013, 06:00:02 AM 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 (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 Thanks so so much for all your help!!! Title: Re: How to start Bitcoind on ubuntu startup Post by: redtwitz on October 11, 2013, 11:50:47 AM Glad you got it working. :)
Title: Re: How to start Bitcoind on ubuntu startup Post by: vindimy on October 13, 2013, 05:59:56 AM 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 (http://community.opscode.com/cookbooks/crypto-coin).
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 Here's what final result looks like: Code: :~$ ps aux|grep coin |