Author

Topic: How to run Bitcoind in the background/startup? (Ubuntu 12.04) (Read 4231 times)

legendary
Activity: 1358
Merit: 1001
https://gliph.me/hUF
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.
legendary
Activity: 1143
Merit: 1000
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.
sr. member
Activity: 910
Merit: 302
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

sr. member
Activity: 276
Merit: 284
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
sr. member
Activity: 280
Merit: 250
lol, anytime!

I'm just a newbie to it, but I found this treasure tucked away Smiley
hero member
Activity: 533
Merit: 500
^Bitcoin Library of Congress.
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
legendary
Activity: 910
Merit: 1000
★YoBit.Net★ 350+ Coins Exchange & Dice
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!
full member
Activity: 168
Merit: 100
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.
sr. member
Activity: 280
Merit: 250
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!
sr. member
Activity: 294
Merit: 250
/etc/rc.local file is also a place where you can insert commands that need to be executed at boot.

legendary
Activity: 1974
Merit: 1029
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).
sr. member
Activity: 266
Merit: 250
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.
newbie
Activity: 30
Merit: 0
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 ...
legendary
Activity: 3682
Merit: 1580
Have you tried changing $cmd to:

Quote
cmd="$home/bin/bitcoind -daemon"
newbie
Activity: 43
Merit: 0
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://bitcointalksearch.org/topic/m.317426

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,

Jump to: