Bitcoin Forum
December 07, 2016, 12:40:41 PM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [Guide] Restart bitcoind automatically if it crashes or dies using Monit  (Read 5153 times)
gjs278
Jr. Member
*
Offline Offline

Activity: 33


View Profile
April 16, 2011, 06:10:40 AM
 #1

This guide is intended for keeping your instance of bitcoind constantly running.

1. Install Monit through your package manager or from the website.

2. Install the latest git ebuild of bitcoind that has pid support. You can tell if you have it by typing bitcoind --help and seeing -pid. You must have a version of bitcoind with pid support.

Code:
Bitcoin version 0.3.21 beta

Usage:
  bitcoin [options]                    
  bitcoin [options] <command> [params]  Send command to -server or bitcoind
  bitcoin [options] help                List commands
  bitcoin [options] help <command>      Get help for a command
Options:
  -conf=<file>       Specify configuration file (default: bitcoin.conf)
  -pid=<file>        Specify pid file (default: bitcoind.pid)

3. Set your monit config file to the following. It should be in /etc/monitrc but check where your package manager installed it. Replace datadir and any other features you may use inside of the start program parameters. If you change the port, make sure you update the failed port section.

Code:
set daemon 60
set logfile /var/log/monit.log

check process bitcoind with pidfile "/var/run/bitcoind.pid"
  start program "/usr/bin/bitcoind -pid=/var/run/bitcoind.pid -datadir=/root/.bitcoin -daemon"
  stop program "/usr/bin/bitcoind stop"
  if 3 restarts within 5 cycles then timeout
  if failed port 8332 for 3 cycles then restart

4. Start monit. It may be in /etc/init.d/monit start or wherever your system installed it. Set it to startup as well so if the machine reboots it will start bitcoind automatically for you.

5. Test it out. Do a bitcoind stop and see if monit auto-restarts it. From now on, if port 8332 doesn't work, the program still stop bitcoind and restart it, which should solve any hanging that occurs due to random crashes.
1481114441
Hero Member
*
Offline Offline

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

1481114441
Report to moderator
1481114441
Hero Member
*
Offline Offline

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

1481114441
Report to moderator
1481114441
Hero Member
*
Offline Offline

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

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

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

1481114441
Report to moderator
1481114441
Hero Member
*
Offline Offline

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

1481114441
Report to moderator
1481114441
Hero Member
*
Offline Offline

Posts: 1481114441

View Profile Personal Message (Offline)

Ignore
1481114441
Reply with quote  #2

1481114441
Report to moderator
Alex Beckenham
Full Member
***
Offline Offline

Activity: 154


View Profile
May 10, 2011, 03:25:39 PM
 #2

Hi there, thanks for the post, but could you please dumb it down a notch for me:


1. Where do you get a version of bitcoin that has the -pid in it?

2. Does the mainstream version from bitcoin.org have -pid in it?

3. Your 'code' block includes a lot of text that doesn't look like code:

eg.
if 3 restarts within 5 cycles then timeout
if failed port 8332 for 3 cycles then restart

Can you explain each part?

4. I thought the port for bitcoin was 8333... why 8332?

5. How do you 'do a bitcoin stop'?


Thanks very much.

davout
Legendary
*
Offline Offline

Activity: 1358


1davout


View Profile WWW
May 10, 2011, 03:33:40 PM
 #3

1. Where do you get a version of bitcoin that has the -pid in it?
Get latest version I'd say or compile latest from source.

3. Your 'code' block includes a lot of text that doesn't look like code:

if 3 restarts within 5 cycles then timeout
if failed port 8332 for 3 cycles then restart
Monit DSL documentation and examples are all over the internet.

5. How do you 'do a bitcoin stop'?
Usually by typing "bitcoin stop" at a command prompt.

Thanks for the snippet! I might complete it with capistrano integration for use in rails apps.

gjs278
Jr. Member
*
Offline Offline

Activity: 33


View Profile
June 06, 2011, 11:58:02 PM
 #4

Hi there, thanks for the post, but could you please dumb it down a notch for me:


1. Where do you get a version of bitcoin that has the -pid in it?

2. Does the mainstream version from bitcoin.org have -pid in it?

3. Your 'code' block includes a lot of text that doesn't look like code:

eg.
if 3 restarts within 5 cycles then timeout
if failed port 8332 for 3 cycles then restart

Can you explain each part?

4. I thought the port for bitcoin was 8333... why 8332?

5. How do you 'do a bitcoin stop'?


Thanks very much.

the current version of bitcoin has pid file support. that part just means that if it can't connect to port 8332 3 times in a row, bitcoind has crashed and needs to be restarted. 8332 is your json api, 8333 is something different.

bitcoind stop will stop the program

also updated the guide to reflect the -daemon change, you now need it for this to work
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!