Bitcoin Forum
May 14, 2024, 09:36:17 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to run Bitcoind in the background/startup? (Ubuntu 12.04)  (Read 4213 times)
chipbike (OP)
Newbie
*
Offline Offline

Activity: 43
Merit: 0



View Profile WWW
January 21, 2014, 10:00:03 PM
Last edit: January 21, 2014, 10:15:21 PM by chipbike
 #1

Hi,

I'm setting up a Bitcoind server in a Ubuntu 12.04.

I'm trying to understand how can I start Bitcoind at boot and keep it running in the background.

For example, if I do:
Code:
# bitcoind -daemon
# ...

The server will start, but if I close the terminal window, the server will shut down after a while.

I've googled some more and found this: https://bitcointalk.org/index.php?topic=25518.msg317426#msg317426

I've tried the solution above, but without success. I've done all the steps but the Bitcoind don't even start.

There are any strategies to keep the Bitcoind running based on things like Supervidord(http://supervisord.org/)?

I accept any clue on how to put Bitcoind starting at boot.

Thanks,

1715679377
Hero Member
*
Offline Offline

Posts: 1715679377

View Profile Personal Message (Offline)

Ignore
1715679377
Reply with quote  #2

1715679377
Report to moderator
1715679377
Hero Member
*
Offline Offline

Posts: 1715679377

View Profile Personal Message (Offline)

Ignore
1715679377
Reply with quote  #2

1715679377
Report to moderator
TalkImg was created especially for hosting images on bitcointalk.org: try it next time you want to post an image
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715679377
Hero Member
*
Offline Offline

Posts: 1715679377

View Profile Personal Message (Offline)

Ignore
1715679377
Reply with quote  #2

1715679377
Report to moderator
1715679377
Hero Member
*
Offline Offline

Posts: 1715679377

View Profile Personal Message (Offline)

Ignore
1715679377
Reply with quote  #2

1715679377
Report to moderator
Abdussamad
Legendary
*
Offline Offline

Activity: 3612
Merit: 1564



View Profile
January 22, 2014, 08:43:29 PM
 #2

Have you tried changing $cmd to:

Quote
cmd="$home/bin/bitcoind -daemon"
rubensayshi
Newbie
*
Offline Offline

Activity: 30
Merit: 0


View Profile
July 17, 2014, 10:34:28 AM
 #3

you could you supervisord for this with a config along the lines of:

Code:
[program:bitcoind]
command=bitcoind -datadir=/home/bitcoin/.bitcoin -daemon=0
user=bitcoin
group=bitcoin
process_name=%(program_name)s
stdout_logfile=/var/log/bitcoind.log
redirect_stderr=true
stdout_logfile_maxbytes=5MB
stdout_logfile_backups=5
stdout_capture_maxbytes=5MB
stopasgroup=true
autostart=true
autorestart=true
startretries=10
startsecs=10
stopwaitsecs=10

the user/group are set to use bitcoin/bitcoin and the -datadir is specified to use "/home/bitcoin/.bitcoin", if you're okay with running everything as root then remove the user/group line and change the datadir to "/root/.bitcoin"
the command includes the -datadir because the $HOME env var isn't set when supervisord starts when your server (re)starts.
the command must include "-daemon=0" because otherwise the process will spawn the daemon with a different PID and then exit and supervisord will see that as a crash!

the other options are just copied from what I'm using, feel free to tweak them as desired, and don't forget that I'm using /var/log/bitcoind.log for logging the output, depending how everything is setup you might not have write access to it ...
zhinkk
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
July 17, 2014, 11:28:06 AM
 #4

Could you achieve this through the use of a crontab? For example, you can run scripts on boot using the @reboot keyword. So if you wanted to run bitcoind, you could add "@reboot bitcoin -daemon" to your crontab.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
July 17, 2014, 11:31:45 AM
 #5

Could you achieve this through the use of a crontab? For example, you can run scripts on boot using the @reboot keyword. So if you wanted to run bitcoind, you could add "@reboot bitcoin -daemon" to your crontab.

That's what I do (but as a regular user, not root).
RedDiamond
Sr. Member
****
Offline Offline

Activity: 294
Merit: 250


View Profile
July 17, 2014, 01:42:35 PM
 #6

/etc/rc.local file is also a place where you can insert commands that need to be executed at boot.

Lucky Cris
Sr. Member
****
Offline Offline

Activity: 280
Merit: 250


View Profile
July 25, 2014, 07:11:26 AM
 #7

Old thread recently bumped... but since it seems it wasn't answered:

I run bitcoind and other coinds on my Unbuntu 12.04 server 24/7.

You'll need to create .config in the .coin directory. Here's a sample config I use:

Code:
rpcuser=username
rpcpassword=verylongpassword
rpcconnect=localhost
listen=1
daemon=1
server=1
disablewallet=1

If the coind is moved to /usr/bin directory, you can start from any directory by just typing the coind in terminal:

Code:
bitcoind

The config I provided ensures the process runs even after you close the terminal.

Here's a cool trick (alternative) I recently learned:

Code:
bitcoind & disown

I use this in my scripts; it releases the process from terminal. For example, if i open Firefox via command line, it'll close when I close my terminal window. But, if I use firefox & disown I can continue to use terminal or close it without it affecting firefox.

Hope this helps someone!

AliceWonder
Full Member
***
Offline Offline

Activity: 168
Merit: 100



View Profile
July 25, 2014, 06:11:12 PM
 #8

Could you achieve this through the use of a crontab? For example, you can run scripts on boot using the @reboot keyword. So if you wanted to run bitcoind, you could add "@reboot bitcoin -daemon" to your crontab.

That's what I do (but as a regular user, not root).

Yup - it's the perfect use for cron.

Once an hour or so start the daemon fron cron (as regular user). If daemon already running, no harm. If not running, it will start.

Other thing I do is once a day I stop it, sleep for three, and start it with the reindex option - that way if there was a problem with the blocks, it gets fixed.

QuarkCoin - what I believe bitcoin was intended to be. On reddit: http://www.reddit.com/r/QuarkCoin/
Justin00
Legendary
*
Offline Offline

Activity: 910
Merit: 1000


★YoBit.Net★ 350+ Coins Exchange & Dice


View Profile
July 25, 2014, 10:19:56 PM
 #9

You sir, deserve the post of the day award!!!
I've been using unix/linux for years now.... never heard of that disown command...

It is very cool Smiley Thanks for posting that up.

Here's a cool trick (alternative) I recently learned:

Code:
bitcoind & disown

I use this in my scripts; it releases the process from terminal. For example, if i open Firefox via command line, it'll close when I close my terminal window. But, if I use firefox & disown I can continue to use terminal or close it without it affecting firefox.

Hope this helps someone!

BookLover
Hero Member
*****
Offline Offline

Activity: 533
Merit: 500


^Bitcoin Library of Congress.


View Profile
July 26, 2014, 12:12:34 AM
 #10

You sir, deserve the post of the day award!!!
I've been using unix/linux for years now.... never heard of that disown command...

It is very cool Smiley Thanks for posting that up.

Here's a cool trick (alternative) I recently learned:

Code:
bitcoind & disown

I use this in my scripts; it releases the process from terminal. For example, if i open Firefox via command line, it'll close when I close my terminal window. But, if I use firefox & disown I can continue to use terminal or close it without it affecting firefox.

Hope this helps someone!
Mr. Forehead meet Mr. Desk.  Great tip, wish I had found this sooner. Wink

Lucky Cris
Sr. Member
****
Offline Offline

Activity: 280
Merit: 250


View Profile
July 26, 2014, 01:24:12 AM
 #11

lol, anytime!

I'm just a newbie to it, but I found this treasure tucked away Smiley

nuno12345
Sr. Member
****
Offline Offline

Activity: 276
Merit: 284


View Profile
July 26, 2014, 02:19:29 PM
 #12

open a new shell and type:
crontab -e
crontab should open, type this at the end:
@reboot /path/to/bitcoind
then hit ctrl+x, yes, enter

reboot and type ps xa | grep "bitcoin", should be a line there Smiley
CryptoPanda
Sr. Member
****
Offline Offline

Activity: 882
Merit: 302


View Profile
January 08, 2015, 07:30:09 PM
 #13

Yes Lucky Cris advices are a treasure (both of them)
It's actually odd this tip about the .conf file is not more widely known


But to truly keep it running 24/7 what you guys do for those cases when the process gets killed for some reason?
Most often it's ram and no swap situation but I guess it happens sometimes on high ram systems too.
So what about those cases?
Any smart trick? Smiley

Reynaldo
Legendary
*
Offline Offline

Activity: 1143
Merit: 1000


View Profile
January 08, 2015, 11:35:54 PM
 #14

You can use screen, you open it up then detach that terminal if you think that closing it is killing the process. For more information: https://wiki.archlinux.org/index.php/GNU_Screen

You can also make a cron to check if its up and then if its not up then re run it.

btw nice one at the disown, will try it.
Newar
Legendary
*
Offline Offline

Activity: 1358
Merit: 1001


https://gliph.me/hUF


View Profile
January 13, 2015, 12:11:35 PM
 #15

Yes Lucky Cris advices are a treasure (both of them)
It's actually odd this tip about the .conf file is not more widely known


But to truly keep it running 24/7 what you guys do for those cases when the process gets killed for some reason?
Most often it's ram and no swap situation but I guess it happens sometimes on high ram systems too.
So what about those cases?
Any smart trick? Smiley


Not pretty, but works: A crontab that starts the process every x Minutes. If bitcoind already runs it will do nothing, but a log entry. Another crontab takes care removing that log file every so often.

Other options include upstart and monit, both of which I had little success on Ubuntu 12.04. My understanding is upstart is working under 14.04. systemd is now availble on 15.04, but I haven't tinkered with that one yet.

OTC rating | GPG keyid 1DC91318EE785FDE | Gliph: lightning bicycle tree music | Mycelium, a swift & secure Bitcoin client for Android | LocalBitcoins
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!